Servlet API deletes cookie instead of over-writing it

J

JehanNYNJ

The first time the user visits I am saving his information in a cookie
with the following code....

cookie = new Cookie(name, _value);
cookie.setMaxAge(MAX_AGE);
response.addCookie(cookie) .

The next time he visits (new session) I am retrieving the cookie
with....

Cookie[] cookies = request.getCookies();
for (int i = 0; i < cookies.length; i++) {
cookie = cookies;
if (name.equals(cookie.getName()))
return cookie;
}

I put a new value in and save it again with...

cookie.setValue(_value);
response.addCookie(cookie);

The problem is that the app server seems to be deleting the cookie on
the system instead of overwriting it. So the third time he logs in it
does not find any cookie....

Anybody seen this behavior? I am running JBoss 4.

Thanks for any help.
 
S

Sanjay

Very strange I have a sample application which does it and every time I
am getting the cookie, unless for the third request user is closing the
browser.

The second time you are setting the cookie as a session cookie which
will be deleted after the browser is closed.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top