The role of cookies I think we all know, in layman's terms, when a user accesses a server through the HTTP protocol, the server returns some Key/value key-value pairs to the client browser and adds some restrictions to the data. The next time the user accesses the server when the condition is met, the data is fully returned to the server.
There are two versions of the current Cookie: The identifier for the response header is "Set-cookie" and "Set-cookie2", respectively. Cookies are version 0 (sometimes referred to as Netscape cookies) and Cookies version 1 (RFC2965).
Version 0
| Property Item |
Property Entry Introduction |
| Name=value |
Key-value pairs, you can set the Key/value to save, note that the name here cannot be the same as the names of other property items |
| Expires |
expiration, the Cookie expires at a certain point in time, such as Expires=wednesday, 09-nov-99 23:12:40 GMT |
| Domain |
The domain name that generated the Cookie, such as domain= "Xulingbo.net" |
| Path |
The Cookie is generated under the current path, such as path=/wp-admin/ |
| Secure |
If this property is set, the Cookie will be returned only when the SSH connection is made. |
Version 1
| Name=value |
Same as Version 0 |
| Version |
The response header created through Set-cookie2 must conform to the RFC2965 specification, if set by the Set-cookie response header, the default value is 0, and if you want to set to 1, the Cookie follows the RFC 2109 specification |
| Comment |
Comment Item, which the user explains what the Cookie is used for |
| Commenturl |
URI comment provided by the server for this Cookie |
| Discard |
Whether to discard the Cookie entry after the end of the session, by default Fasle |
| Domain |
Similar to Version 0 |
| Max-age |
The maximum failure time, unlike Version 0, is how many seconds it is set to expire. |
| Path |
Similar to Version 0 |
| Port |
The Cookie can be returned to the server under what port, if there are multiple ports, separated by commas, such as port= "80,81,8080" |
| Secure |
Similar to Version 0 |
format:
You can have multiple name/value, separated by semicolons. If there are other properties such as path, they are also key-value pairs and separated by semicolons. such as Set-cookie:name=value; Name=value; Expires=date; Path=path;domain=domain_name; SECURE.
Use the following:
Need to use Javax.servlet.http.Cookie object, this object supports Version0 and Version1, but individual properties cannot be set.
HttpServletRequest request httpservletresponse Responsecookie cookie = new Cookie ("CookieName", "Cookievalue"); Cookie.setmaxage (3600); Response.addcookie (cookie);
The other property settings are similar. To obtain a cookie, the following:
cookie[] cookies = request.getcookies (); for (Cookie cookie:cookies) { cookie.getname (); Cookie.getvalue (); }
Java Cookie Explanation