?
Solved

How do delete cookies in IE8 with JSP?

Posted on 2009-04-29
3
Medium Priority
?
973 Views
Last Modified: 2012-08-14
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.
<%
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);
%>

Open in new window

0
Comment
Question by:merlinds333
2 Comments
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 1000 total points
ID: 24270742
try -1 instead of 0
0
 
LVL 1

Expert Comment

by:SiNT4X
ID: 26166452
Hello merlinds333 :)

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.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Australian government abolished Visa 457 earlier this April and this article describes how this decision might affect Australian IT scene and IT experts.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question