Configure Session Timeout in Servlet - Web.xml
The session timeout can be configured in two ways -
1. Specify the session timeout in (web.xml)
You need to use session-config tag in web.xml. Specify the session timeout in minutes in session-config .
This is how you can do it.
<web-app ...>
<session-config>
<session-timeout>20</session-timeout>
</session-config>
</web-app>
This will kill the servlet container on 20 minutes of inactive session .
2. Timeout with setMaxInactiveInterval()
HttpSession session = request.getSession();
session.setMaxInactiveInterval(20*60);
The above setting is only apply on session which call the
“setMaxInactiveInterval()” method, and session will be kill by container
if client doesn’t make any request after 20 minutes.
Note - Here the interval is in seconds