Document.cookie= "info=" +name+ "," +PASSW + ";"; Store cookies
var info = document.cookie.split (";"); Read cookies
A cookie in ①js is the end of a ";" that represents the end of a data in a cookie.
② in a cookie file, the cookie data exists as a key-value pair, which means that only one of the same names is allowed.
JS Read cookies:
Get the value of a cookie according to the name
function Getcookieval (cookiename)
{
var search = cookiename + "="
var returnvalue = "";
if (Document.cookie.length > 0)
{
offset = document.cookie.indexOf (search);
if (offset!=-1)
{
Offset + = Search.length
End = Document.cookie.indexOf (";", offset);
if (end = = 1)
end = Document.cookie.length;
Returnvalue=decodeuricomponent (document.cookie.substring (offset, end));
}
}
returnvalue = Returnvalue.replace (/\ "/g,"); Replace all double quotes
Return returnvalue;
}
Java Delete cookies:
/**
* Delete Cookies
* @param cookiename
* @param response
* @param request
*/
private void Deletecookie (httpservletresponse response, HttpServletRequest request) {
cookie[] cookies = request.getcookies ();
if (cookies!= null && cookies.length > 0) {
for (int i = 0; i < cookies.length; i++) {
Cookie Tmpcookie = new Cookie (Cookies[i].getname (), Cookies[i].getvalue ());
Tmpcookie.setmaxage (0);
Tmpcookie.setpath ("/");
Response.addcookie (Tmpcookie);
}
}
}
Java adds a value to a cookie:
Cookie cookie = new Cookie (name of cookie, value of cookie);
Cookie.setpath ("/");
Cookie.setmaxage (99999999);
Response.addcookie (cookie);
Reference: http://mojianpo.iteye.com/blog/1137122
If you want to see JS write cookies, search in Baidu, anyway, Java Cookie,js can read, JS write, Java can also read. More and more like using cookies.