The session object in the JSP page is detailed

Source: Internet
Author: User
Tags session id

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.