A little note written by a cookie (transcription)

Source: Internet
Author: User

Cookies are text that is stored on the client side and can improve the user experience to some extent. The Servlet API provides a cookie class that allows you to create a cookie object and save the cookie to the client through the Addcookie method in the response.

The concept and use of cookies:
Cookies are text that is saved on the client
The Servlet API provides a cookie class that encapsulates text information into cookie objects
The Addcookie method is provided in the HttpServletResponse interface to add cookies to the response
The GetCookie method is provided in the HttpServletRequest interface to obtain all cookie objects from the request

To elicit a cookie:
After landing a website, use the same machine to log in again, do not need to enter the user name and password, has been automatically logged in.
This functionality is often implemented as a cookie.
Cookies are text stored on the client, and text is often present in the form of key-value pairs. Cookies are saved to the client after the browser accesses the site using the cookie. Cookies are automatically passed to the server side as the cookie is stored on the client and the server-side resources are accessed again. It is important to note that some confidential information should not be stored in a cookie, such as a bank card password.

Cookies:
Cookie (string name, String value)
Constructs a cookie with a specified name and value.
int Getmaxage ()
Returns The maximum age of the cookies, specified in seconds, by default,-1 indicating the cookie would persist until brows ER shutdown.
Sets the effective duration of the cookie object, which defaults to 1, that is, the cookie expires after the browser is closed, and the cookie information is saved on the hard disk
String GetName ()
Returns the name of the cookie. Gets the name of the cookie object
String GetValue ()
Returns the value of the cookie. Gets the value of the cookie object
HttpServletRequest:
Cookie[] GetCookies ()
Returns an array containing all of the cookies objects the client sent with this request.
HttpServletResponse:
void Addcookie (Cookie cookie)
Adds the specified cookie to the response.

To delete a cookie:
Setting the cookie's presence time to 0 seconds deletes the cookie.
C.setmaxage (0);

Jsessionid Cookies
View a cookie named Jsessionid by experiment
The value of Jsessionid is a random integer
Prepare for learning sessions in later chapters

Special Cookie: A cookie named Jsessionid
We found that the first access page did not get a cookie, but refreshing the page or re-accessing the page without closing the browser gets a cookie named Jsessionid, which is unchanged in the same browser regardless of the number of times it is accessed.

A cookie with the name Jsessionid we can tell that it is a session cookie.
He is the cookie used to implement the session mechanism: By default, when the JSP is accessed, the server side generates a cookie named Jsessionid, which is a random 16-binary integer

A little note written by a cookie (transcription)

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.