Tomcat change session timeout

12 points
Created by:

1. Open web.xml

web.xml location:


2. Change value of <session-timeout>30</session-timeout>

After we opened web.xml, we need to find <session-timeout> tag in xml and we can change it to other value.

<!-- ==================== Default Session Configuration ================= -->
<!-- You can set the default session timeout (in minutes) for all newly   -->
<!-- created sessions by modifying the value below.                       -->

session-timeout value is defined in minutes


  • to set to 1h set session-timeout value to 60
  • to set to 24h set session-timeout value to 1440


  • 60 min - 1h
  • 1440 min - 24h (24*60) - 1 day


  • Set session timeout to 60 min (1h)
  • Set session timeout to 1440 min (24h)

3. Restart tomcat

With Intellij IDEA - restart tomcat from IDEA level.

If we run tomcat on windows:

  • apache-tomcat-8.5.38\bin\
  • apache-tomcat-8.5.38\bin\

If we run tomcat on windows:

  • apache-tomcat-8.5.38\bin\shutdown.bat
  • apache-tomcat-8.5.38\bin\startup.bat

4. Second way to do it - Timeout per individual Session

We can set session timeout programmatically for each request.

The way to do it:

import javax.servlet.http.HttpSession;

HttpSession session = request.getSession();
session.setMaxInactiveInterval(1440); // 24h

Read more

  1. JavaEE - HttpSession.setMaxInactiveInterval(int)
  2. Spring session - setMaxInactiveInterval(java.time.Duration interval)
  3. Apache tomcat - setSessionTimeout(int)

Checkout latest findings & news:

Checkout latest questions:

Checkout latest wiki articles:

Hey 👋
Would you like to know what we do?
  • Dirask is a friendly IT community for learners, professionals and hobbyists to share their knowledge and help each other in extraordinary easy way.
  • We welcome everyone,
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.
Rockstar community members
Thank you for great work 👍