Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to set session expiration time in Javaweb

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report