Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to update expiration date of cookie

843842Jun 24 2008 — edited Jun 25 2008
Hi. How to update expiration date of cookie? Say I have a cookie that remembers the user's token for 3 weeks. A copy of the token value is stored in the database on the server. After a week the user logs in. The expiration date of the cookie should now be 3 weeks from the time of this last login.

When I called
Cookie[] cookies = httpServletRequest.getCookies();
Cookie cookie = ...;
cookie.setMaxAge(... 3 weeks ...);
httpServletResponse.addCookie(cookie);
then on the browser I saw there were two cookies with the same name -- one with the original expiry date, and the other with the new expiry date.

Not calling httpServletResponse.addCookie(cookie) has no effect.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 23 2008
Added on Jun 24 2008
3 comments
670 views