Servlet- three domain objects

 Request
Request is a request, just send a request will create a request, its scope: valid only if the current request.

Use: used in the same between the server request parameter transfer between different pages, often used in the form of transfer control value.

Commonly used methods:

request.setAttribute ();

request.getAttribute ();

request.removeAttribute ();

request.getParameter ().

2, session
server creates a session object for each session, so session data is available in the current session All servlet share.

Session: the user opens the browser session began, until you close the browser session will end. Creating a session object only once during a session.

Use: commonly used in web development login verification interface (when the browser assign a session key that the user logs on successfully).

Method:

session.setAttribute ();

session.getAttribute ();

session.removeAttribute ();

Method session object is obtained:
in the Servlet: HttpSession session = request.getSession ();
since the session belongs to one of the nine jsp built-in objects, are It can be used directly. For example: <% session.serAttribute ( "name" , "admin")%>.

Note: session is a server-side object, stored on the server side. Sessionid generated and the server can be created after the session back to the client through a cookie, so that the next verification. (Session depends on the underlying Cookie)

. 3, the Application (the ServletContext)
Range: All the users can obtain this information, this information is retained across the entire server. Application range of property value, as long as the set once, then all pages can obtain the data window. ServletContext is created when the server starts, destroyed when the server shuts down, only a JavaWeb application creates a ServletContext object.
Application object acquisition method (Servlet in):

    the ServletContext this.getServletContext XC = ();
    xc.setAttribute ( "name", "SW"); // set a value into


    the ServletContext this.getServletContext XC1 = ();
   xc1.getAttribute ( "name"); // get key-value pairs  

Guess you like

Origin www.cnblogs.com/sy130908/p/11576278.html