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

What is the basis of Session?

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article is to share with you about the basis of Session, the editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.

Because Cookie has a great limitation, Session appears.

The function of Session is to save some user's data on the server, and then pass to the user a Cookie named JSESSIONID, so in essence it is also a Cookie, this JESSIONID corresponds to a Session object in the server, through which you can get the Session that stores the user's information.

What is Session?

First, Session is one of the nine built-in objects in jsp.

Second, Session is a domain object

Then Session is a technology used to store user data on the server side. And Session session technology is based on Cookie.

Creation and acquisition of Session

The Session is created when the request.getSession () method is first called.

Add: the call after request.getSession () is to get the created Session object, singleton pattern

After the Session is created, a Cookie named JSESSIONID is also created.

The default aging of this Cookie is the current session.

How Session works

After the Session is created, the corresponding Cookie is saved to the browser, and then the browser carries the Cookie every time it visits the project.

When we call again, we will get the existing Cookie based on the JSESSIONID instead of creating a new Cookie.

If there is a JSESSIONID in the Cookie, but the JSESSIONID does not have a corresponding Session, a HttpSession object is recreated and the JSESSIONID is reset.

Access to Session data

SetAttribute setting Properties

GetAttribute get attribute

The scope of Session is the current session, that is, a corresponding browser client, a browser, a session object, not a web page.

Effective time of Session

The Session object cannot be saved for a long time on the server side, it has a time limit, and the Session object that has not been accessed for a certain period of time should be released to save memory. Session's timing starts from the last time it is accessed, counting its "idle" time.

Description: the default maximum valid time for Session objects is 30 minutes. In the web.xml configuration file under the conf directory of tomcat

Set up

The Session session timeout we configured in the web.xml file is valid for all Session.

SetMaxInactiveInterval (intseconds) sets how long the Session expires after the user has no action. In seconds.

If it's a positive number. Indicates that the Session session expires if the user does not take any action at a given time.

If it is a non-positive number (zero-negative). Indicates that Session never expires.

IntgetMaxInactiveInterval () gets the timeout. In seconds.

Forced failure of invalidate ()

Activation and Passivation of Session

Session passivation: when Session is not in use or shuts down the server for a period of time, the process of serializing data from existing Session objects and Session objects to disk is called passivation.

Session activation: after Session is passivated, when the server calls the Session object again or restarts the server, the process of deserializing the data in the Session object and Session object from disk to memory is called activation.

If you want objects in the Session scope to be serialized to disk along with the Session passivation process, the object's implementation class must also implement the java.io.Serializable interface. Not only that, if the object also contains references to other objects, the associated object must also support serialization.

The above is the basis of Session, and the editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

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

Development

Wechat

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

12
Report