How do delete cookies in IE8 with JSP?

Posted on 2009-04-29
Last Modified: 2012-08-14
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","");



        Cookie1 = new Cookie ("Product2","");





Open in new window

Question by:merlinds333
    LVL 75

    Accepted Solution

    try -1 instead of 0
    LVL 1

    Expert Comment

    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 "":

    "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: . 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.

    Featured Post

    Course: CSS Specialist

    We don’t have to sell you on the idea of becoming a developer. If you’re you here, you already know it’s one of the most lucrative (and fastest growing) career tracks out there. It’s CSS that allows you to set yourself apart from other web and mobile developers.

    Join & Write a Comment

    Introduction The Google Maps API offers various ways to draw dynamic and static maps.  Using a combination of PHP and JavaScript, you can draw active JavaScript maps that allow pan-and-zoom in the client browser window.  You can also draw "static" …
    Envision that you are chipping away at another e-business site with a team of pundit developers and designers. Everything seems, by all accounts, to be going easily.
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

    729 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

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now