I run development on Tomcat 6.0.29 and IE 8. I need help to understand behavior of cookies. I created a new cookie and setup maxAge to 60 seconds running script setMaxAge(60). I expected this cookie to be persistent and to exist for 60 seconds. I ran this script to create the cookie Cookie newCookie = new Cookie(request.getParameter("cookiename"), request.getParameter("cookievalue"));
newCookie.setMaxAge(60); response.addCookie(newCookie); That is what I found: When I display maxAge by getMaxAge, I get -1, not 60 as I expected Cookie was actually alive for 60 seconds (as it was supposed to be) while a browser was opened even though getMaxAge() returned -1. Cookie was not persistent. It means when I closed all browsers and opened one again in less than 60 seconds, I found the cookie disappeared. I expected the cookie to be saved on my computer and exist after starting a browser within maximum age. Please explain this behavior of cookie.