Cookie operation in JSP

xiaoxiao2021-03-06  116

Cookie Concept: The format of the cookie is actually a pure text message, which is sent to the client along with the webpage and saves the directory specified in the client hard disk. Everyone has a serious security threat, In fact, it is not such a thing. When the server reads cookies, only the information related to this server is only read. Moreover, the browser is generally only allowed to store 300 cookies, each site is mostly 20, and each cookie The size is now in 4k, and it will not take much space at all. And cookie is time-efficient. For example, the survival time set of cookies is 1 minute, then this cookie will be deleted by the browser after a minute.

Cookie version:

There are currently two versions:

Version 0: It is also supported by Netscape, which is also supported by almost all browser. In order to maintain compatibility, only to the version 0, cookie content can not be spaced, square brackets, parentheses, equal to the number (=) , Comma, double quotes, slash, question mark, @ symbol, colon, semicolon.

Version 1: Based on the RFC 2109 document. Receive a lot of restrictions. The characters listed above can be used. But in order to maintain compatibility, you should try to avoid using these special characters.

The operation of cookie in JSP:

Type method method explains StringgetComment () Returns a comment in cookie. If you do not have a comment, return null value. StringgetDomain () Returns the domain name applicable to cookies in cookies. Use the getdomain () method to indicate the browser to return cookies to the same domain The server, and usually the cookie only returns the exact same server as the server name sent. Note that the domain name must return intGetMaxage () to return to the maximum time before the cookie expire, calculate in seconds. StringgetName () Returns the name StringgetPath () returns the path to the cookie. If the path is not specified, the cookie will return to all the pages in the current page where the current page is located and its subdirectory. BooleangetSecure () If the browser sends cookies through the security protocol, returns the true value if the browser uses the standard protocol, returns a false value. StringgetValue () Returns the value of the cookie. The author will also introduce GetValue / SetValue later. IntgetVersion () Returns the version of the protocol complied with Cookies. VoidSetComment Settings Cookies Note VoidSetDomain (String Pattern) Set the cookies for cookies VoidSetMaxage (int Expiry) in seconds, set the cookie expiration time. VoidSetPath (String Uri) Specifies the path to the cookie. VoidsetSecure (Boolean Flag) Indicates the security protocol used by the browser, such as HTTPS or SSL. VoidSetValue (String NewValue) Cookies created a new value. VoidsetVersion (INT V) Sets the protocol version of Cookies

转载请注明原文地址:https://www.9cbs.com/read-126452.html

New Post(0)