This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Hi All, I am trying to delete a cookie via a servlet when user clicks "logout" button but it doesn't work. I have a cookie with following settings, Cookie c = new Cookie("mycookie","maulin"); c.setPath("/"); c.setDomain(".myco.com"); when I set the cookie upon login. On Logout button click submission I am reading all cookies where I see "mycookie" as well and then have the following code,
The above code doesn't remove the cookie from the browser BUT if I write, temp.setMaxAge(0); temp.setDomain(".myco.com"); temp.setPath("/"); then it works. Why? When I do temp = c[i] where c[i] has Domain and Path set then why I have to repeat the settings before I add the new cookie 'temp' to the response with max age 0? Regards Maulin
Joined: Nov 04, 2001
anybody has any idea? OR my question is not clear? Regards Maulin
When this is done, the cookie disappears as advertised. It's curious that this behavior is not documented anywhere on the internet or in any of my numerous books. Your posting on JavaRanch was the only reference I found, and it solved my problem. Thanks!
Joined: Oct 11, 2002
ok, the domain and path in the second reference should match the first: