The three main built-in objects of JSP here are: Request,session and application. They shared the method: Setattribute,getattribute, the method name and method function are all the same, but the scope of action is different, which is related to the scope of the 3 objects. Use the following simple visitor count examples to illustrate:
<body>
<%if (Application.getattribute ("Count") ==null)
{
Application.setattribute ("Count", 1);
}
else{
String Counti=application.getattribute ("Count"). ToString ();
int Counter=integer.parseint (counti);
counter++;
Application.setattribute ("Count", integer.tostring (counter));
}
%>
You are the <%=application.getattribute ("Count")%>-bit visitor.
</body>
The SetAttribute and GetAttribute methods of the Request,session and application objects are used to represent the above example.
Experimental results and Summary:
1, Application object: As long as the server does not shut down, the count will not be zeroed, using different client (browser) Access will accumulate count.
2. Session object: Access is counted, but the access behavior of different clients is not correlated, and the number of times after closing the client (browser) is zeroed, (each session is independent).
3. Request object: Access is not counted. (The request is separate from the request, so each new request--the number of times will be cleared after the end of the response 0).
An example of JSP three important built-in object life cycle