JSP (Java Server Page) JSP state management

Source: Internet
Author: User

Two mechanisms to save the state of a user (Cookie Session)

1.Cookie (Web server saves text messages on the client)

1.1 Effects:
1. Tracking for a specific object
2. Save user's web browsing history and habits
3. Simplified login operation
1.2 Disadvantages:
There is a security risk, easy to disclose user information

1.3 Creating/Using Cookies
1. Create a Cookie Object
Cookie cookie = new cookie (String key,object obj);
2. Write Cookie Object
Response.addcookie (cookie);
3. Read cookies
cookie[] cookies = request.getcookies ();

1.4 Common methods:

Method name Describe

void setmaxage (int expiry)

Set the lifetime of the cookie, in seconds
void SetValue (String value) After creating a cookie, assign a value to the cookie
String GetName () Get the name of the cookie
String GetValue () Get the value of a cookie
int Getmaxage () Gets the effective time of the cookie, in seconds

2.Session and Cookie Differences

Session Cookies
Describe Saving user information on the server Saving user information on the client
Object type is saved in session When a cookie is saved, string type
Destroys data stored by the end of the session Cookies can be stored for a long time on the client
Save Important information Save non-critical user information

JSP (Java Server Page) JSP state management

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.