Java web.xml session-config attribute configuration

In Java Web development, Session provides a lot of convenience for us, Session is made between the browser and server maintenance. Session Timeout understood as: Creating a Session between the browser and the server, because the client for a long time (sleep time) did not interact with the server, the server destroy this Session, the client again when the previous Session server interaction does not exist a.

Setting Session Timeout way:

Way: web.xml disposed in code works as session-config, in terms of a single application is directed to:

 
 <the session-config>
  <-the session timeout> 2 </-the session timeout>
 </ the session-config>
 i.e. client and server interaction twice the longest interval of 2 minutes, 2 minutes session.getAttribute () acquired is empty

 API information:

 
  session.getCreationTime () Gets the creation time of the session
  session.getLastAccessedTime () Gets the last time interaction with the server
  session.getMaxInactiveInterval () Gets the maximum time interval session inactivity, in seconds, 120 seconds.
Second way: session-config, in the default value in the Tomcat /conf/web.xml: 30 minutes, for the purposes of the entire container

<the session-config>
        <-the session timeout> 30 </-the session timeout>
</ the session-config>
Three ways: disposed in a Servlet

 
  The session = Request.getSession the HttpSession ();
  session.setMaxInactiveInterval (60); // seconds
Description:

 1. Priority: Servlet API provided in> Settings program /web.xml> Tomcat / conf / web.xml provided

 2. The client and the server once an effective session (session has not timed out), each time the same access sessionId, if the code is set session.setMaxInactiveInterval () value, a maximum inactivity interval the session is to be modified, and applied as a the new value.

 3.Session destruction (the end of the session on behalf of cycles): in a period called a request session.invalidate () method, the end of this period the request, session is destroyed; or automatically destroyed after the session timeout; client or off out browser

Summary: In the development process, we can check with the server every client interaction SessionID (Session property value, the non-HttpServlet development environment can also be used in place of other Key value) for session management.

Guess you like

Origin blog.csdn.net/qq_36838191/article/details/91382562