views:

569

answers:

1

All,

Although I see related topics on the forum, but I don't see a clear solution on this issue. I am trying to set a javax.servlet.http.Cookie with an expiration time (so that it persists across browser sessions). Code:

public void respond(HttpServletRequest req, HttpServletResponse resp) {
 int expiration = 3600;
 Cookie cookie = new Cookie("TestCookie", "xyz");
 cookie.setDomain("");
 cookie.setVersion(0);
 cookie.setPath("/");
 cookie.setMaxAge(expiration);
 cookie.setSecure(false);
 resp.addCookie(cookie);
}

I don't see this cookie being set when I check in IE developer tools. Searching on the internet gave me clues that IE doesn't consider Max-Age, but only works with Expires. If this does not work for IE, then is there a proven way of setting the HTTP response headers for a persistent cookie so that it works for IE?

PS: This works fine on all other browsers.

I tried creating a string for the cookie having expires attribute. IE succeeded in creating it, but it lost the domain (default - "") and showed ".com" and turned it into a session cookie instead of a persistent cookie. This again works fine on all other browsers.

Please help. Thanks.

A: 

The answer is at http://stackoverflow.com/questions/361231/persistent-cookies-from-a-servlet-in-ie/.

Your case may be a different flavour of the same issue: that is, by prefixing the domain with a "." (which I'm pretty sure is a version 1 cookie feature), something in the Java stack decides it's a version 1 cookie (unrecognized and not persisted by IE, even IE8) and sends that cookie format.

Or, as that answer suggests, is there something in your cookie value that contains an unrecognized character?

Intellectual Tortoise