Scope::
Request < Session < application
Each corresponding interface
The interface that corresponds to the request object:
Javax.servlet.ServletRequest its sub-interface:javax.servlet.http.HttpServletRequest
Interface for session object:javax.servlet.http.HttpSession
Interface for application objects:javax.servlet.ServletContext
Three common methods:
SetAttribute (string name, Object o), getattribute (string name);
Simple analysis of three people:
1.request
Call the above two methods, only on a single request (forwarding not count the request, because the forwarding is the server-side behavior) in effect, when the information returned to the client, the object is destroyed
2.session
Concept:
is the server-side behavior
Used to track the status of the customer, when the user to visit a site, the server will generate a SessionID for the customer, in a cookie way to return to the client, when the customer to visit the site's other services, will bring the current SessionID Together to make a request, has identified which user, a user is like a Session object, do not interfere.
Operating mechanism:
Session Failure Reason:
1) Session expires
2) server-side call invalidate () to invalidate it
3) Now the majority of the page is to support the session, to let the page lose the session effect,
Add <%@ page session= "false" to%>, but this is not normally done
Important methods of Session:
1) getId ()---Get the ID number of the session, each ID number is different
2) isnew ()---Judge if the session is new
3) Invalidate ()---Let the current session expire and release resources
4) setmaxinactiveinterval (int interval)---Set the time interval (in seconds) at which the session is inactive.
Over that time, the session expires,
If you set a negative number, or 0, you do not limit the session inactivity interval, which is typically 30 minutes by default
5) SetAttribute (string name, Object o), getattribute (string name)
Application Scenarios:
1) Login
2) Shopping Cart
3.application
call the above two methods , a server on a Application object, the user shared a application, when the server stopped application was destroyed, (for site visits)
----------------------------------------------
Transfer from http://blog.csdn.net/hzc543806053/article/details/7416007
Request,session,application, three comparisons