Save session after restarting java browser
I am working on a small project using java servlets / jstl
I have created a login with a session and I want the browser to persist this session even after the browser.
I wrote this code:
HttpSession session=request.getSession();
session.setMaxInactiveInterval(604800);
session.setAttribute("loggedOnUser", true);
I have set the session timeout to a week. But whenever I close my browser and reopen it, I need to login again. When I look at my browser's cookies, the cookie containing the sessionId still expires when the browser is closed. I thought that "setMaxInactiveInterval" would change this for one week. Does anyone know what the problem is?
I suggest setting a maximum age for this cookie:
HttpSession session = request.getSession();
Cookie cookie = new Cookie("JSESSIONID", session.getId());
cookie.setMaxAge(Integer.MAX_VALUE);
response.addCookie(cookie);
when the browser restarts any browser, it deletes the cookies, which is why when after restarting when creating a new request server it does not see the cookie in the request and treats it as a new session