Setting Session Timeout in JSP Servlet

Session can die in following three ways in J2EE application:

  1. Its Time out
  2. invalidate() method called on Session Object
  3. Application goes down (Application crashes or undeployed)

Method 1: Configuring session timeout in the DD

Session Time out can be configured in DD (Deployment Descriptor / web.xml) and it has virtually same effect as calling setMaxInactiveInterval() on every session that is created :


Note : Argument in tag is in minutes. In above example its 15 minutes.

Method 2:  Setting Session timeout for the specific session object

If you want to change the session timeout for any particular session then we can call below method on that Session :


Note : the argument passed in method setMaxInactiveInterval() is in seconds. In Above example its 30 minutes.

Leave a comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.