By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,468 Members | 1,865 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,468 IT Pros & Developers. It's quick & easy.

Problem with storing Cookies

P: n/a
Hi there,

I have a problem with storing my Cookies. I made a servlet in which I
store a Cookie (in the doGet()-method) to detect whether a user has
already visited my webpage.

I used the following code:

Cookie c = new Cookie("sessionID", generateSessionID());
c.setMaxAge(60*60*24*365);
response.addCookie(c);

To test the Cookie I surfed to another website and then returned to my
servlet.
When I tried to retrieve the Cookie (with
HttpServletRequest.getCookies()) no Cookies were returned. The same
thing happened when I closed my browser, opened it again and returned
to my servlet. My browser is set to accept all posiible Cookies. Does
anybody know a solution to my problem?

Thanks in advance!
Jul 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Make sure the cookie is set before the response being flushed or
committed, otherwise it would mean that the header has been sent to
the client, and cookie info should be contained in the header.
Bl**************@hotmail.com (Blossom) wrote in message news:<9b**************************@posting.google. com>...
Hi there,

I have a problem with storing my Cookies. I made a servlet in which I
store a Cookie (in the doGet()-method) to detect whether a user has
already visited my webpage.

I used the following code:

Cookie c = new Cookie("sessionID", generateSessionID());
c.setMaxAge(60*60*24*365);
response.addCookie(c);

To test the Cookie I surfed to another website and then returned to my
servlet.
When I tried to retrieve the Cookie (with
HttpServletRequest.getCookies()) no Cookies were returned. The same
thing happened when I closed my browser, opened it again and returned
to my servlet. My browser is set to accept all posiible Cookies. Does
anybody know a solution to my problem?

Thanks in advance!

Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.