Quantcast
Channel: Active questions tagged servlets - Stack Overflow
Viewing all articles
Browse latest Browse all 675

Do I need to call HttpSession.getSession() method everyt time to keep session alive?

$
0
0

I am reading about HttpSession interface and I am not sure if I understand session expiry correct. Please correct me if I am wrong in this rough case example scenario:

  1. The client visits website and on the server side I need to create session (it is not created automatically by default as far as I understand) by calling HttpServeltRequest.getSession().
  2. After that HttpSession object is created JSSESIONID associated with this object is sent as a cookie with HttpServletResponse
  3. Next time user sends HttpServletRequest it will have that cookie with JSSESSIONID attached.
  4. HttpSession object get's destroyed after some inactivity set by HttpSession.setMaxInactiveInterval()

I have few questions:

  • Am I correct assuming that calling HttpServletRequest.getSession() checks if there is a cookie with JSSESSIONID received with request and it's value used to check if there is a HttpSession object stored in servlet and if not new HttpSession object is created and id attached a cookie?
  • Do I need to explicitly call HttpServletRequest.getSession() to keep session alive or does servlet automatically check on every request if there is a JSSESSIONID received and updates last accessed time of HttpSession object?

Viewing all articles
Browse latest Browse all 675

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>