application built-in objects
application data sharing between users
void setAttribute (String key, Object value ) in key stored in the form of object values alue
Object getAttribute (String key) Gets the value of the object by key
transactions String getRealPath (String path) Returns the relative path path
statistics site visits:
<%
// get the current site visits
Integer COUNT = (Integer) application.getAttribute ( "COUNT");
IF (COUNT = null!) {
COUNT ++;
} the else {
COUNT = 1;
}
the Application .setAttribute ( "COUNT", COUNT);
%>
<%
out.print ( "current site visits:" + application.getAttribute ( "COUNT"));
%>
scope
From small to large: Page (pageContext) ---> request ----> session ----> the Application
Page Object Scope effective only on the current page
valid request scope is requested within the current
session is scope in the current session effective within
the scope of application objects in the application context is
a common method cookie object: void setMaxAge (int expiry): validity set a cookie, in seconds; void setValue (String value): after the cookie is created for the cookie given new values; String getName (): Gets the cookie name; String getValue (): Gets the value of the cookie; int getMaxAge (): Gets the effective time of the cookie, in seconds; use the cookie: create a cookie object: cookie newCookie = new cookie (String name, String value) ; write cookie: response.addCookie (newCookie); read cookie: <% response.addcookie (new cookie ( "username", "jack")); response.addcookie (new cookie ( "password", "123456") ); response.sendRedirect ( "info.jsp");%> cookie is valid:
cookie and session scope objects: session scope is stored in the server-side user information, cookie information is stored in the user client; the role of session saved field value is of type object, cookie stored value is of type String; session scope with the end of the session and store their data destruction, cookie may be saved in the long-term clients; cookie is typically used to store user information is not important, important information using the session scope to save;
Data Exchange (ii)
Guess you like
Origin www.cnblogs.com/lowerma/p/11139429.html
Recommended
Ranking