Cookie concept: stores a string attribute on the client, and obtains a string when reading the cookie value. Besides the name and value, there are also expires expiration time, path, domain, and secure security.
The Cookie of JS Code is worth saving: cookie is a string attribute of the document. To save the cookie, you only need to create a string in the format of name = <value> (name = value), and then set the document. cookie of the document to be equal to it. Example:
Document. cookie = "username" + username;
The Cookie of JS Code is worth reading:
// Define the cookie for storing Variables
Var strCookie = document. cookie;
// Cut multiple cookies into multiple name/value pairs
Var arrCookie = strCookie. split (";");
// Traverse the cookie array to process each cookie pair
For (var I = 0; I <arrCookie. length; I ++ ){
Var arr = arrCookie [I]. split ("= ");
// Find the cookie named userId and return its value
If ("userId" = arr [0]) {
User = arr [1];
Break;
}
}
Conclusion: keep cookies simple. Do not rely on the existence of cookies. Do not store too much information in each cookie. Do not save too many cookes. However, in the hands of skilled WEB administrators, the concept of cookie is a useful tool.
Session concept: string attributes stored on the server;
Session value storage: session. setAttribute ("name", name );
Session worth reading:
String num = (String) session. getAttribute ("name ");
// Returns the Object, which can be forcibly modeled as a string;
From song lixing's column