ASP object structure

zhaozj2021-02-16  122

Now we have to understand the object structure of the ASP, then, you can give it an anti-three, don't use too much to explain every example. This part may be difficult.

First, the Request Request object saves the customer information in several collections for the ASP application. The general access method is: Request.Collection ("MEMBERNAME") When you do not specify a collection name, all collections are searched in (1) QueryString, (2) Form, (3) cookie and (4) ServerVariable order, When the first matched variable, he determined that he is a member to reference. Of course, in order to improve efficiency, you'd better explicitly specify the members in that collection. QueryString Collection When the HTML form is passed to the ASP file, the data is saved in the collection queryString. Its member can have multiple values ​​associated with it, that is, in the same form, multiple elements can have the same name, the following code access these data: <% for each item in request.QueryString ("name" ) Response.write item & "
" Next%> Form Set When the form is single with the POST method, the data is saved in the Form collection. The ServerVariable collection saves the information of the HTTP header with the HTTP request. You can get the information about the browser. The main members are: remote_addr Request_Method request method (such as Post, Head) Remote_HOST Request_Method request method (such as pos, get, head ) Server_name server name server_protocol server version number (such as HTTP / 1.0)

Second, the Response object is used to control the contents of HTML returned to customers, have several properties and methods. The following describes what I think is important: Buffer Property If True, the content of Response is to write into the buffer, and then send it to the customer when the script is processed. The Status property passes the status of the HTTP Response packet. The status code returned by the server consists of three digits, which can be used for testing phases and conversion to control to other sites (ie, Forward) WRITE methods to output HTML to customers, which can be any legal HTML script. Redirect method causes the browser to redirect to another a URL, such as: <% browsetype = Request.ServerVariables ( "HTTP_USER_AGENT") IF Left (browsetype, 11) = "Mozilla / 2.0" thenResponse.Redirect "FancyStart.asp" ElseResponse. Redirect "OldStart.asp" END IF%> CLEAR method If you set the buffer property to true, the CLEAR method knows all buffer content. The flush method will send the buffer content to the customer. End method When Active Server encounters this method, stop processing ASP files immediately if there is a buffer, and send content to customers immediately. BinaryWrite method outputs binary data

Third, the request object and the response object of the cookies collection 1. Write the cookies response.cookies ("Cookie Name") [("key name"). Properties] = value If the cookie already exists, the value is replaced by the new value, otherwise Create this cookie, for example: <% response.cookies ("new cookie") = "New cookie value"%> 2. Read cookies such as: <% = Request.cookies ("NewCookie")%> cookies also have some properties, See the relevant information. 4. Application object Active Server application is a virtual directory and all files in its subdirectory, namely a web. You can share information in all users of the application object, and you can hold data during server running. He has some methods and events that control access to application layer data. Application itself does not have a built-in attribute, and there is a user-defined: Application ("Attribute Name) = Value Saves data in the Application object can be read by all users of the Application. If you are used to do access: Application ("Avisits") = Application ("Avisits") 1 method has two: LOCK: When the user calls Lock, only the current user can edit or add the properties of the Application object. UNLOCK: Be sure to remember, call the Lock, be sure to call UNLOCK. Events There are two: Application_onstart events: Call when the application starts. Application_onstart event: Call when the application terminates. These two events plus the handlers of the session of the two events in the file global.asp, and a web application has only one global.asa file and placed in the root directory of the application. Examples of a global.asp file are as follows: