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 :

<web-app>
...
<servlet>
....
</servlet>
<session-config>
    <session-timeout>15<session-timeout>
</session-config>
</web-app>

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 :

session.setMaxInactiveInterval(30*60);

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

Posted

in

,

by

Tags:


Related Posts

Comments

Leave a Reply

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

Discover more from Jitendra Zaa

Subscribe now to keep reading and get access to the full archive.

Continue Reading