Session and Application objects

Source: Internet
Author: User

First, session and application

1, session of the Relationship diagram

Show the session ID

The code is as follows:

1, first create a t1.jsp page, create a session, set the key and value

2. Then create an additional t2.jsp page to get the value of session in T1.jsp

can also be re-assigned to the session

Summarize:

The client's session is actually a sign of which browser your request came from

Question 1: Is it always the same?

A: Restart the browser, your session ID will change,

The result is that the data that was previously saved on the server cannot be retrieved.

Issue 2: Assuming that the client's session ID is not changed (the browser does not restart),

So will the server keep the session data?

Answer: The server (Tomcat) if 20 minutes, no one moves,

Then this session will be destroyed automatically.

Session scenario: Generally, it is used to record your login information

2, Application

Diagram of Application

Code:

Basically consistent with the session

1. First create a a1.jsp page, create a application, and set the key and value

2, then create another ta2.jsp page, get the value of application in a1.jsp,

Summary of application:

For application throughout the project, there are only 1 variables, and all clients share the same Application object.

Human society, is to solve the problem of the allocation of resources

What are the application scenarios for resource sharing?

1. Grab train Tickets

2. Lottery

3. Count clicks

The similarities and differences between session attributes and application

1, session and application, request in configuration properties, code-like

2, session for each user (browser) is separate, and all users of application (browser) is a shared one. From the perspective of use, sharing the same 1 variables will cause a conflict of resource contention. (Most of the time you don't have to application)

3. The session server is only saved for 20 minutes by default (modifiable), and application will persist until Tomcat shuts down.

Session and Application objects

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.