Use jsp to save data

Source: Internet
Author: User

1. Session Save User Name
We often encounter this situation when surfing the Internet:
Automatically log on after successful registration
After logging on, remember the user status and display the user name on multiple pages.

In fact, these effects use a built-in object of the session, which is also called a session.
To put it simply, when we access the server through a browser, we have a conversation with the server.
Sessions allow us to store and use data in multiple requests using browsers and servers
First, after successful registration, we can save a token related to you in the session, for example, your user name.
Then you can jump to other pages to check whether the session has a flag related to you.

 

Each session has a unique sessionid, which is generated by the server and sent to your browser as the response is received.
Your browser will remember this ID, and will carry this ID when you want the server to send a request later
If the server obtains the sessionid in the request, it can find the corresponding SESSION on the server side.

 

Without an appropriate cleanup mechanism, the number of sessions saved by the server increases, leading to server crashes.
For servers, there are two ways to clear data:
1. The Program actively requests to clear data, such as the logout function after logon.
2. The server will take the initiative to clear sessions that haven't resending the request for a long time.


Ii. automatically enter the user name for Cookie
When the browser is closed, the session ends, but automatic logon is also enabled. the user name is automatically filled in on the page every time you access the mailbox.
The Cookie is used to save data as a file.
The Cookie stores data as a file on the client. If someone steals the file, the private data will be exposed.

3. Implement counters in application
On some pages, we can see the number of visits to this page.
To implement this function, you need to use the application object.
Each WEB project has an Application object.
The application object can share usage data throughout the project.
Each time you access the page, the counter is added with 1


Iv. Comparison of various storage objects
The data stored in the request can only be used in one request.
The data stored in the session is available within the validity period of a session. For example, when the browser session is closed, the data is lost.
The data stored in the application is the longest in the entire web project, and can be used as long as the server does not stop,
Suitable for data that needs to be shared and accessed by the entire project or used by multiple users.

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.