Cookies
1, the technology of saving HTTP status information on the client
2, the server read the cookie is issued from the browser, he saved in the request header heavy
3. Access to Cookies
Cookie Cookie=new Cookie ("name", "value");
4/Common methods
Cookies. Setmaxage (valid time value)//If no valid time is set, the cookie is not written to the client hard disk and the cookie is destroyed when the browser is closed
SetName (), SetValue (), GetName (), GetValue ();
Response.addcookie (cookie); //Add a cookie in response
Request GetCookies ()//Returns an array of cookie types, and then uses GetName (), GetValue () to visit his name, and value
Session
1. Session Life cycle
1. Created when the browser accesses the server,
2. The session closes when the browser is closed
3, the session does not set the validity period, all browser closed session revocation
Note: Therefore, you need to set the validity period in the session in the e-commerce servlet
2. Creation of Session
HttpSession session=request.getsession ()
Request.getsession (FALSE); //Read session only and not create
3. Session usage is cookie-based
There will be a session ID when the session is created.
The ID is returned to the browser in the form of a cookie, which is brought to the Servlet,servlet by the ID to receive the session in response to the browser's other actions.
The ID is returned to the browser in the form of a cookie, but the validity period is not set
HttpSession session=request.getsession ();
String Sessionid=session.getid ();
Cookie Cookie=new Cookie ("Jsessionid", SessionID)//jsessionid The default cookie value, which is overridden in order to reach the purpose of overwriting
Cookie.setpath ("/project directory")//
Cookie.setmaxage (30*60); //Set cookie expiration date
Response.addcookie (cookie)//Return to Browser cookie
Session.setattribute ("name", "value"); //Set the value of session
4. Closing of Session
Default Time to
Manual forced Shutdown----session.invalidate ()
Server is not properly shut down
The server shuts down normally----session passivation (Session Resurrection)
Disable in the cookie, can I use the session?
Yes, can be bound to the Address bar recodeurl (String URL);
This article is from the "design mode" blog, so be sure to keep this source http://6250716.blog.51cto.com/6240716/1603964
Cookies and session