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