I am having trouble deleting cookies from my servlet code. Below is my code.
private void clearCookies(HttpServletRequest req, HttpServletResponse resp) {
Cookie[] cookies = req.getCookies();
for (Cookie curCookie : cookies) {
curCookie.setValue(null);
curCookie.setMaxAge(0);
curCookie.setPath("/");
resp.addCookie(curCookie);
}
}
After calling the method, I do resp.sendRedirect (url). However, not all cookies are deleted, for example, this cookie is never deleted.
Name: reqURI
Content: ../../webapp/index.jsp
Domain: mgt.appserver.com
Path: /
Send for: Any kind of connection
Accessible to script: Yes
Created: Tuesday, November 26, 2013 4:35:19 PM
Expires: When the browsing session ends
Does anyone know what I'm missing here? I have read the documentation for the Java Cookie object and, according to this value of 0, I must delete the cookie. But this is not so. And I tried many more suggestions, and none of them worked. I tried this with Google Chrome and Firefox, so I can't believe this is a problem with browsers. I have no idea why such a generic thing is improperly documented and compiled in the Java language.