Cookies
Today, I would like to say a cookie, because in the classroom I do not understand, so, if it is said to be a blog, rather than my review notes, haha
First publish a cookie schematic
1. What is a Cookie?
"A cookie is a variable stored on a visitor's computer. This cookie is sent whenever a page is requested by the same computer through a browser. You can use JSP to create and retrieve the value of a cookie. ”
A cookie is a file created by a visited website that stores browsing information, such as profile information.
From the JSP point of view, a cookie is some string information. This information is stored on the client computer and is used to pass information between the client computer and the server.
This information can be read or set through Document.cookie in the JSP.
2.Cookie Basic Usage
A. Simple access operation
The cookie property of the Document object must be used when accessing cookies using JavaScript, and a line of code describes how to create and modify a cookie:
Document.cookie = ' Username=darren '
In the above code ' username ' denotes the cookie name, ' Darren ' indicates the value corresponding to the name. If the cookie name does not exist, then a new cookie is created, and if it exists, the value corresponding to the cookie name is modified. If you want to create a cookie multiple times, use this method again.
3.JSP Cookie in Chinese garbled solution
We may have garbled characters when we use cookies.
This is a workaround found on the Web:
Save cookies
String value = Java.net.URLEncoder.encode ("You need to save the Chinese");
Cookie Namecookie = new Cookie ("Draftflow_username", value);
Cookie Usercookie = new Cookie ("Draftflow_user", user);
Namecookie.setmaxage (60*60*24*30*365);
Namecookie.setpath ("/");
Response.addcookie (Namecookie);
Read cookies
cookie[] cookies = request.getcookies (); if (cookies!=null) { = ""; for (int i = 0; i < cookies.length; i++) { = cookies[i]; if (C.getname (). Equalsignorecase ("Draftflow_username")) { =java.net.urldecoder.decode (C.getvalue ()); // decoding } }
}
4. How to perform the add delete operation
<%new Cookie ("AName", "Avalue"%> ======================================= <%newnull); Killmycookie.setmaxage (0); Killmycookie.setpath ("/"
Just write us a lot, and I'm going to see the jquery easy Ui (tre tree) detailed blog next time goodbye!!!
Review the JSP foundation of Jsp/servlet Technology (detailed second)