I understand that a JSP session cookie is not persistent. Once all browser instances are closed, the session cookie is gone.

Derek Illchuk

In the JSP page, I inserted the following:

<% Cookie sessionCookie = new Cookie("JSESSIONID", session.getId());
sessionCookie.setMaxAge(1800);
sessionCookie.setPath("/examples");
response.addCookie(sessionCookie);
%>

What this does is it rewrites the non-persistent session cookie created automatically (non-persistent because no expiration is specified) to the same one, but having an expiration (using setMaxAge()). The setPath must be identical to the original, and the name (JSESSIONID) must be identical, as well. Now, because of the expiration, this cookie is not deleted on exit, and contains the exact info as the original (using getId()).

It works great! Remember, the session information is still on the server until it times out (half an hour).

Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact