web state management

state management web
1: http protocol is stateless connections using
2: For each container is a request from a new user

Implementing a state tracking mode
1: Using hidden form fields only in the dynamic transmission, which occurs if a static page, you can not reach the state track

2: cookie method to produce a cookie on the server object, the object is an object keyvalue, Step 2 cookie object inlaid into the response header Step 3 The packed data in response to the browser parses the data cookie file information stored in the future if this made a request, the server returns the server cookie read procedures

Data acquisition request cookie
request, getCookie ();
Set Cookie life cycle of
cookie.setMaxAge ();


Cookie data to address unsafe technology
3: Session technology
generates a session object on the server, generating a session id, the id will respond to this in the form of a cookie to the browser, the browser stores in the browser cookie data to local file format next id cookie data is sent at the time of the request, and then find the corresponding server parses the session, then get the data


4: url rewriting
1: Hyperlink
2: rewrite url path

// Get the session object that there may be new but the old
HttpSession session = request.getSession ();
so we need to judge
the use of if (session.isNew ()) {// If the object is new return to true

} // if the else {return false} old

session life cycle
is the beginning and end of a session

Destroy the session object
1: Set the session timeout object. setMaxInactiveInterval () Method
2: Calling invalidate () method on the session object
3: The End (crashes or cancel the deployment)
4: destroy the cookie file

session warehouse
than a request large, small than the context
save a session object
objects .setAttribute ();
Gets a session object
objects .getAttribute ()

session warehouse thread safe thing?
1: If the person operating it is absolutely safe
2: Use a script is not safe


3 large scope of servlet
session, request, servletContext


Common distortion
1: page charset garbled Mate
2: Request parameter distortion Request.setCharacterEncoding (the arg0);
. 3: garbled response resp.setContentType ( "text / HTML; charset = UTF-. 8");
. 4: SQL distortion characterEncoding = utf- 8"

Guess you like

Origin www.cnblogs.com/caohua95/p/12081215.html