Rohitesh Rohitesh - 4 years ago 107
Java Question

Cookies are not setting in some clients

I am facing a slightly weird problem. I am setting a cookie in my Java Servlet, and accessing it later. This works when I am accessing my webapp from

certain machines
. However, from others, it is not working.

On further analysis, I found that the cookie is not setting in some browsers. However, in the same browser,
another cookie
I am setting in another part of my webapp, is
successfully stored
. Anyone else has faced similar issues before?

Details :
OS : Windows XP

Browser : Mozilla Firefox 3.6.13

Code :

tempCookie = new Cookie("CN.checkCookie", "try this!!!");
tempCookie.setMaxAge(60 * 60 * 24 * 365);

Another observation :

When the cookie setting fails, I have also seen that variables stored previously in the session variable, are also lost.



Answer Source

Sounds like privacy configuration in your browser. Check it. As far as I remember your can configure privacy in browsers per URL. This may explain this strange behavior.

Additionally I'd recommend you to call setDomain() and setPath() explicitly.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download