I'm working on a small project with java servlets/jstl
I've created a login with a session and I want the browser to keep that session even after a browserrestart.
I've written this code:
HttpSession session=request.getSession();
session.setMaxInactiveInterval(604800);
session.setAttribute("loggedOnUser", true);
I've set the session timeout to a week. But whenever I close the browser and reopen it I need to login again. When I look at the cookies of my browser, the cookie that contains the sessionId still expires when the browser closes. I thought "setMaxInactiveInterval" would change that to one week. Does anyone know what the problem is?
I suggest setting the max-age of that cookie:
HttpSession session = request.getSession();
Cookie cookie = new Cookie("JSESSIONID", session.getId());
cookie.setMaxAge(Integer.MAX_VALUE);
response.addCookie(cookie);
when browser restarts some browser deletes cookies and that is why when after restart when you make new request server doesn't see cookie in request and treats it as a new session
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With