merlinds333
asked on
How do delete cookies in IE8 with JSP?
Hello,
We are working on an old site that uses JSP. We were able to delete cookies historically on logout using the code below. We tested the site on IE8 today and this technique no longer works. Does anyone have a workaround?
Thanks in advance.
We are working on an old site that uses JSP. We were able to delete cookies historically on logout using the code below. We tested the site on IE8 today and this technique no longer works. Does anyone have a workaround?
Thanks in advance.
<%
Cookie Cookie = null;
Cookie Cookie1 = null;
Cookie = new Cookie ("Product1","");
Cookie.setPath("/");
response.addCookie(Cookie);
Cookie1 = new Cookie ("Product2","");
Cookie1.setPath("/");
Cookie1.setMaxAge(0);
response.addCookie(Cookie1);
%>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
In JSP, the setMaxAge method does not work in IE8. Along with that, setting the cookie's maxage to -1 would cause it to persist until the browser is closed, and NOT be deleted instantly.
Quoted from "http://www.roseindia.net/jsp/jspcookies.shtml":
"Negative values indicate the default behavior: the cookie is not stored persistently, and will be deleted when the user web browser exits."
Instead, you need to use a header call to utilize the "expires=date" and "Max-Age=0". I found a guide with a perfect example of the issue at this post: http://forums.sun.com/thread.jspa?messageID=10865308#10865308 . Take a look at the function "addCookie(Cookie cookie)" - it explains the entire header call, as it is quite large.
Just make sure that, in the end, you differentiate between IE and other browsers, because while setMaxAge doesn't work in IE8, the header call doesn't work in some other browsers.