register
other register

Tuesday, September 15, 2009

Remove Cookie in Servlet

In Firefox, view the cookie info via Web Developer plugin. Make sure the path is correct, that is where the cookie located.



 


 


In Servlet, to remove a named cookie do:

Cookie myCookie = new Cookie("JSESSIONID", "");
myCookie.setMaxAge(0);
myCookie.setPath("/");
//myCookie.setPath("/" + grailsApplication.metadata['app.name']);
response.addCookie(myCookie);

Refer to the Java Servlet Cookie doc, set the MaxAge to 0 will delete the cookie.

No comments: