The Request,session and application of Web beginner

Source: Internet
Author: User

Request

(1) Request setattribute () Span style= "font-family: the song Body;" > with getattribute () setattribute () Methods set properties and property values, Then through getattribute () Method gets the object value corresponding to the property based on the property. setattribute () and getattribute () ( note :getattribute () after a downward type conversion is required, convert the property value to a True object )

(2) the getparameter () method of request is to obtain the parameter value sent by the client through the form or URL request parameter, which is the interaction between the client and the server. To obtain the data sent by the client, the server needs to use the getparameter () method to obtain it. There is no setparameter () method corresponding to it .

Session

(1) Session also exists setattribute () getattribute () Span style= "font-family: the song Body;" > method. But with request different, session session object's survival range ( As long as the browser does not close, session ) So, in the same browser window, Regardless of how many requests are sent to the server, session

(2) The survival scope of the data within the Request object is within the scope of the request object's survival, when the client sends a request to the server, and the server returns a response to the client, the requested object is destroyed ; when you then send a new request to the server, the server creates a new Request object, the Request object to the previous Request object locks the object without any relationship, and therefore cannot get the Request the data that the object holds.

Application

(1) The object with the largest surviving range, as long as the server is not closed, the data in the Application object will persist. There is only one application during the entire server run .

Contact and distinction: the range ofrequest,session , and application3 objects is incremented by one; the request is within the scope of the browser's serial port;theapplication is in the process of running the entire server.

Example: Implement a Web page counter to simulate the scope of three objects.

request.jsp

<%if(Request.getattribute ("counter") = =NULL) {Request.setattribute ("Counter", "1"); }            Else{System.out.println ("Else"); String Strnum=NULL; Strnum= (String) request.getattribute ("Counter"); inticount = 0; Icount=integer.valueof (strnum). Intvalue (); Icount++; Request.setattribute ("Counter", Integer.tostring (icount)); }        %>you are the first<%= Request.getattribute ("counter")%>-bit visitor!

Under the Request object, refresh the Web site, and the counters remain unchanged. (The Request object is requested once every time the request is refreshed, and the server is destroyed when it returns a response.) )

Change the Request object in the code to the Session object. Run again.

:                 before closing the browser                                                             

To change the browser to run again, the session object's survival range expires after closing the browser or changing the browser.

The last changed code in the Session object is the Application object. Run. At this point the server is not turned off, two browsers are enabled, and the discovery is still valid.

The Request,session and application of Web beginner

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.