Detailed explanation of the Session object on the JSP page

Source: Internet
Author: User

Session: when a user opens a browser and accesses a website, the server allocates a space for the browser in the memory of the server, and the modification space is exclusive to the browser. This

Session: when a user opens a browser and accesses a website, the server allocates a space for the browser in the memory of the server, and the modification space is exclusive to the browser. This space is the session space. The default data storage time in this control is 30 minutes, which can be modified. Session. setMaxInactiveInterval (n seconds );

Session usage:

1. Shopping Cart in online shopping mall

2. save login user information

3. Put some data into the session for each page of the same user 4. Prevent Unauthorized user logon to a page

How to Understand Session:

The session can be viewed as a table with two columns. Each row is a property of the session. Each attribute contains two parts: the name of the attribute (String) and the value of the attribute (Object ).

How to Use Session:

1. Get the session

In servlet: HttpSession hs = request. getSession (true );

In JSP, session is a built-in object that can be directly used,

2. Add attributes to the session

Servlet: hs. setAttribute (String name, Object o)

Session. setAttribute (String name, Object o) in JSP)

3. Obtain an attribute from the session

In servlet: hs. getAttribute (String name );

In JSP: session. getAttribute (String name );

4. delete an attribute from the session

In servlet: hs. removeAttribute (String name );

In JSP: session. removeAttribute (String name );

Session considerations

1. The default time for Attribute existence in a session is 30 min. You can also modify the time for Attribute existence: a. modify web. xml B in tomacat and modify it in the program.

2. The above mentioned 30 Minutes indicates the user's daze time, rather than the accumulated time.

3. When a browser accesses a website, the server will fly and the browser will assign a unique session id to distinguish different browsers (clients)

4. Because each session attribute needs to occupy the server's memory, software companies are forced to use it. A. Save User Information B. Save the shopping cart

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.