Servlet Session Timeout

I am writing my SPring MVC web application.

I set the session time of the session to 10080 minutes, equal to 1 week. Now I would like the user to register every time he opens the browser:

sessionService.setcurrentUser(myuser);
      HttpSession session = request.getSession();
      Cookie cookie = new Cookie("JSESSIONID", session.getId());
      cookie.setMaxAge(timeout);
      response.addCookie(cookie);

Should my Max Age cookie be the same as the session time?

cookie.setMaxAge(10080);

Is this a good practice?

+3
source share
3 answers

You use cookies to indicate a session ID. If the cookie timeout is below the session, it will no longer find your session. Therefore, it is recommended that you specify a timeout for your cookie at least for the duration of your session.

+1
source

web.xml, cookie .

<session-config>
    <session-timeout>10080</session-timeout>
</session-config>

, / .

+7

.
, , , :

  • : .
  • The effects of memory, your session will be serialized, and you want to minimize it. Especially if the number of users can increase dramatically.

Discussion 1
Discussion 2
Discussion 3

+2
source

Source: https://habr.com/ru/post/1773581/