Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to set session expiration time in Javaweb

Shulou Source: shulou.com Published: 2022-06-02 08:33:26 09月11日 Update

Javaweb how to set session expiration time, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can gain something.

Set the Session timeout mode

Method 1: set session-config in web.xml

As follows:

two

That is, the longest interval between the client and the server for two consecutive interactions is 2 minutes, and the value obtained by session.getAttribute () is empty after 2 minutes.

API Information:

Session.getCreationTime (); / / get the creation time of the session session.getLastAccessedTime (); / get the last interaction time with the server session.getMaxInactiveInterval (); / / get the maximum inactivity interval of the session, in seconds, 120 seconds. Method 2: in / conf/web.xml of Tomcat

Session-config. Default: 30 minutes.

Method 3: set HttpSession session = request.getSession () in Servlet; session.setMaxInactiveInterval (60); / / description in seconds

1. Priority: API setting > Program / web.xml setting > Tomcat/conf/web.xml setting in Servlet

two。 If the session of the access server times out (the interval between this visit and the last visit is greater than the maximum inactivity of session), that is, the last session ends, but a new session occurs between the server and the client, and all the attribute values in the previous session are lost, resulting in a new sesssionId.

3. The client and the server have a valid session (session does not time out), and each visit to the sessionId is the same. If the session.setMaxInactiveInterval () value is set in the code, then the maximum inactivity interval of the session will be modified and applied to the new value.

Destruction of 4.Session (which represents the end of the session period): the Session.invalidate () method is called during a request period. After the request period ends, the session is destroyed, or the session is automatically destroyed after it times out, or the client shuts down the browser.

5. For JSP, if specified, the built-in session variable cannot be accessed directly in JSP, and the session is not actively created, because JSP does not automatically perform a request.getSession () operation to get session at this time.

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Tags: Time server service customer client way maximum cycle center activity unit help longest effective clear same active code representative priority Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Shulou Information Linux Huawei Xiaomi