In the ASP programming language, there are several object structures, namely Request object, Response object, Application object, Session object, Server object, FileSystem object, TextStream object, etc. These objects are useful for technical developers who use ASP language programming. Say, it is very important. Technology developers use these objects almost all the time. The use of these objects is also relatively simple. The editor below will briefly introduce how to use them.
1. Request object
The function of the Request object is to save the request information received by this page in several collections for use by the ASP page. Its general calling method is: Request.Collection (parameter), where Collection is a collection, which can be one of the following: QueryString, Form, Cookie, ServerVariable.
When you do not specify a collection name, that is, when you use the method Request (parameter), the system defaults to QueryString, which is equivalent to Request.QueryString (parameter). When the request information cannot be obtained with QueryString, the system will use other methods. method to obtain request information. The system's default search order is (1) QueryString, (2) Form, (3) Cookie, (4) ServerVariable to search all collections. When the first matching variable is found, it is deemed to be The member to reference. Of course, when we write ASP programs, in order to improve efficiency, you'd better be able to explicitly specify which collection the members are.
(1)QueryString collection
When the HTML form uses the GET method to transfer request data to the ASP web page file, the data will be saved in the collection QueryString. At this time, we can use Request.QueryString (parameter) to obtain the value of the parameter.
(2)Form collection
When used in HTML forms
When the form uses the POST method to transfer request data to the ASP web page file, the data will be saved in the Form collection. At this time, we can use Request.Form (parameter) to obtain the value of the parameter.(3)Cookie collection
Obtaining the cookie set is relatively complicated and is rarely used in general web programming, so we ignore it here. Interested persons can additionally look for technical information in this area.
(4)ServerVariable collection
This collection saves the information of the HTTP header transmitted along with the HTTP request. Information about the browser can be obtained through it. The main parameter members can be as follows:
REMOTE_ADDR remote host IP address
REMOTE_HOST remote host name
REMOTE_USER customer name
REQUEST_METHOD request method (such as POST, GET, HEAD)
SERVER_NAME server name
SERVER_PROTOCOL server version number (such as HTTP/1.0)
2. Response object
Its function is to return HTML content to the client. There are several attributes and methods for its use. Its more important attributes and usage are briefly introduced below:
(1)Status attribute
Pass the status of the HTTP Response message. The status code returned by the server consists of three digits and can be used in the testing phase and transition control to other sites (i.e. Forward)
(2)Write method
Output HTML text to the client, which can be any legal HTML script.
(3)Redirect method
Redirect the browser from the current page to another URL page
(4)End method
When the server specifies this method, it immediately stops various processing tasks and the execution of the web page ends here.
(5)BinaryWrite method
Output binary data to the client. This method can be used to output a picture of the verification code.
3. Cookies collection of Request object and Response object
(1)Write Cookies
Response.Cookies(Cookie name)[(key name).Attribute]=value
If the cookie already exists, the value is replaced by the new value, otherwise, the cookie is created
For example: <% Response.Cookies(NewCookie)=New Cookie Value %>
(2)Read Cookies
For example: <%=Request.Cookies(NewCookie)%>
4. Application object
Active Server application is all the files in the virtual directory and its subdirectories, that is, a WEB website. You can use the Application object to share information among all users of the application and to persist the data while the server is running. This object has methods and events that control access to application layer data.
Application itself has no built-in properties and can be user-defined: Application (property name) = value
The data stored in the Application object can be read by all users of the Application. If used to count visits: Application(aVisits)=Application(aVisits)+1
This object has two methods:
(1)Lock:
When a user calls Lock, only the current user can edit or add properties of the Application object.
(2)Unlock:
Be sure to remember that after calling Lock, you must call Unlock when completed.
There are also two events:
(1)Application_OnStart event: called when the application starts.
(2)Application_OnStart event: called when the application terminates.
These two events plus the two event handlers of Session are placed in the file Global.asp. A Web application has only one Global.asa file, and it is placed in the root directory of the application. An example of a Global.asp file is as follows: