Session: When a user opens a browser and accesses a Web site, the server allocates a space in the server's memory for the browser, which is exclusive to the browser. This one
Session: When a user opens a browser and accesses a Web site, the server allocates a space in the server's memory for the browser, which is exclusive to the browser. This space is the session space, the control of the data default storage time of 30min, you can modify. Session.setmaxinactiveinterval (n seconds);
The usefulness of the session:
1 shopping cart in the online mall
2 Save logged in user information
3 Put some data into the session for each page of the same user to use 4 to prevent users from illegally logging on to a page
How to understand session:
You can think of the session as a table with two columns. Each row is a property of the session. Each property contains two parts, one is the name of the property (String), and the other is its value (Object).
How to use session:
1 Get session
In the servlet: HttpSession hs=request.getsession (TRUE);
In JSP, the session is a built-in object that you can use directly,
2 adding properties to session
Servlet: Hs.setattribute (String name,object o)
Session.setattribute in JSP (String name,object O)
3 Get a property from session
Servlet: Hs.getattribute (String name);
JSP: Session.getattribute (String name);
4 Delete a property from session
Servlet: Hs.removeattribute (String name);
JSP: Session.removeattribute (String name);
Session Considerations
1 The default time for a property in session is 30min, you can also modify the time it exists: A modify the Web.xml B in Tomacat to modify in the program
2. The 30min mentioned above refers to the user's daze time, not the cumulative time.
3. When a browser accesses a Web site, the server flies the browser to assign a unique session ID, which distinguishes the different browsers (i.e. the client)
4. Because each attribute of the session occupies the memory of the server, the software company is used only when it is compelled to do so. A Save the user information B save the Cart