HttpSession: setMaxInactiveInterval(int arg0) : HttpSession « javax.servlet.http « Java by API






HttpSession: setMaxInactiveInterval(int arg0)

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class SessionTimer extends HttpServlet {

  public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException,
      IOException {
    res.setContentType("text/html");
    PrintWriter out = res.getWriter();

    HttpSession session = req.getSession();

    out.println("<HTML><HEAD><TITLE>SessionTimer</TITLE></HEAD>");
    out.println("<BODY><H1>Session Timer</H1>");

    out.println("The previous timeout was " + session.getMaxInactiveInterval());
    out.println("<BR>");

    session.setMaxInactiveInterval(2 * 60 * 60); // two hours

    out.println("The newly assigned timeout is " + session.getMaxInactiveInterval());

    out.println("</BODY></HTML>");
  }
}

           
       








Related examples in the same category

1.bindings.listener
2.HttpSession: getAttribute(String key)
3.HttpSession: getAttributeNames()
4.HttpSession: getCreationTime()
5.HttpSession: getId()
6.HttpSession: getLastAccessedTime()
7.HttpSession: getLastAccessedTime() (2)
8.HttpSession: getMaxInactiveInterval()
9.HttpSession: invalidate()
10.HttpSession: isNew()
11.HttpSession: setAttribute(String key, Object value)