How to set session max inactive time?

14,236

In doPost or doGet method in your servlet, first get Session object and call setMaxInactiveInterval() method on Session. You can similarly get session object & set max inactive interval (by calling setMaxInactiveInterval() method) from your JSP page.

Below is servlet example:

    // Get the current session object, create one if necessary
    HttpSession session = req.getSession();
    // Set the timeout
    session.setMaxInactiveInterval(2*60*60);  // two hours

You can find similar and more examples related to Servlet and sessions here :http://www.java2s.com/Tutorial/Java/0400__Servlet/ServletSessionMaxInactiveInterval.htm

Share:
14,236

Related videos on Youtube

Eswar
Author by

Eswar

Updated on April 27, 2022

Comments

  • Eswar
    Eswar about 2 years

    I get the session MaxInactiveInterval time using the following query. I am developing web application using JSF Framework

    var sessionMaxInactiveTime = ${pageContext.session.maxInactiveInterval};
    

    I need to set maxInactiveInterval.
    how to set maxInactiveInterval using JavaScript, JQuery, or to write Servlet.
    But i want to control to main template jsp Page.

    Is available any links, notes or samples?

    Help me. Thanks in advance.