ASP built-in Object Request and Respones

Source: Internet
Author: User

Basic Asp object
Asp (Active Server Page) is an object-oriented programming language similar to VB. Here, we do not want to detail some basic concepts such as objects, but directly introduce their language features, so that developers can skillfully modify and compile asp programs (because many developers simply use development tools such as InterDev to generate asp programs ).
First, the archive name of the Asp program must be "asp". Second, in the asp program, the Script on the server side should be placed in the middle of the string, for example. If you want to call another Asp file in an Asp file, you can add the following statement in Asp: <! -- # Include virtual | FILE = "***. asp" -->, which is similar to # include in C. Virtual indicates the Virtual File path, and File indicates the real File path.
Asp has five main built-in objects: Request, Response, Server, Session, and Application. The following describes the Request and Response.
1. Request
Asp still follows the popular method of using the Form on the client for data exchange. The Asp built-in request object has five methods to obtain client data (QueryString/Form/Cookies/ServerVariables/ClientCertificate ).
Syntax: request. Method Name ("parameter") | request ("parameter ")
If the latter is used, the system automatically selects the corresponding method.
Form
Here we re-emphasize some attributes of Form:
Enctype = MIME form of Data Transmission
Method = Method of data transmission Get/Post
Onrest = program called by pressing the rest key
Onsubmit = press the sumit key to call the program
Target = frame window of the output content>
There are three methods to transmit information by using Form: transmitting information from Form on the html webpage to other Asp; transmitting information from Form in Asp to another Asp; information in Asp is transmitted to itself.
Syntax: Request. Form (parameter) [(INDEX)]
The parameter indicates the name of the element in Form, and the index indicates the sequence number of the element with the same name.
Example:
Users can be read cyclically. Count is the system attribute of Form and is used to calculate the number of elements with the same name. If the element does not exist, the value is zero. If it does not specify the number of elements with the same name to be read, the system reads the values of all elements with the same name and uses "," as the interval.
Example: Request. form ("user") = abc, bcd, cde
2. QueryString
Syntax: Request. QueryString (parameter) [(INDEX)]
In addition to using Form to transmit data, you can also connect "?" You can use Request. QueryString ("user") to read the transmitted information. If multiple parameters with the same name appear, for example
Resquest. QueryString ("user") = abc, second time
Resquest. QueryString ("user") = bcd, third time
Resquest. QueryString ("user") = cde.
3. ServerVariables
Syntax: ServerVariables (parameter name)
We know that the Web/Browse transmission protocol is http, And the http header has some client information, such
Customer IP address, browser language system, etc. In this case, you can obtain relevant information through Request. ServerVariables ("***"), such as Request. ServerVariables ("Accept_Language"), to obtain the language family of the client browser. Other system parameters are shown in the following table:
The name or IP address of the server.
SERVER_PORT server is running port number
REQUEST_METHOD: Method for sending a request (GET/POST/HEAD
The path to which the SCRIPT_NAME program is called, for example, cgi-bin/a. pl.
The name of the remote machine (client) That REMOTE_HOST sends the request.
The IP address of the remote machine (client) That REMOTE_ADDR sends the request.
The name of the user whose REMOTE_IDENT sends the request (if it is a dial-up Internet access, it is the user ID). This variable is valid when NCSA IdentityCheck is enabled and the client machine supports RFC 931.
MIME Type of CONTENT_TYPE data, for example, "text/html ".
List of MIME types acceptable to HTTP_ACCEPT client.
The type of browser in which HTTP_USER_AGENT client sends a request.
HTTP_REFERER refers to the text URL of the client before reading the CGI program.
4. Cookies
On the client side, Cookies record a lot of information about the client browser. the cookie ("name") command can also be used to obtain its value through Response. cookies ("name") = "value" records some information on the client to control visitors. The method for setting multiple Cookies is Response. Cookies ("name") ("name") = "value ".
5. Cache
We can select the page information that has been accessed from the Cache in the browser. Similarly, we can perform similar settings in the Asp program. Response. Clear indicates clearing the client memory. Response. Buffer = True set to read data from the Cache (False by default ).
6. ClientCertificate
ClientCertificate is used to obtain the Identity confirmation information of the client browser in accordance with the X.509 standard), but the client browser must support SSL3.0 or PCT1 protocol. Here we need to do two steps. Step 1: The web server must start the client authentication option; Step 2: Set the client browser so that this method will take effect. Otherwise, returns the empty value.
2. Response
To transfer data from the server to the client, use the following method:
1) Response. Write directly outputs information, such as Response. write "".
2) Response. redirect directs the client to another url location, such as Response. redirect "http://zyr.yeah.net", but here there is a problem to note, that is, the statement must be executed before the mark, that is, the server will be executed before the server does not send the html text header to the client, otherwise, a transmission error occurs.
3) Response. contentType controls the output file type. The data packet type sent from the server to the client can be text/html or gif/jpeg. Therefore, before each transmission, we must all inform the client of the file type to be transmitted, which is generally "Text/Html" by default.
4) Response. Cookies are used to set the cookie value. Syntax: Response. Cookies (variable name) [(key) | attribute] = written information. The usage of key has been described earlier. It is not described here. By default, the cookies system has five attributes, including the Expires time), Domain name), Path), and Secure security) haskeys checks whether there are other cookies ).
5) Response. Buffer is used to determine whether information is transmitted to the Buffer. Because sometimes we want to send some intermediate information to the buffer and continue to work. After all the processing work is completed, the information is output to the client. However, when the Flush or End method is called during processing, the buffer content is output.
Other Response attributes:
Expires: Set the length of time for retaining the web page in the client browser.
ExpiresAbsolute: set the date and time when the webpage is retained in the client browser.
Other Response methods:
AddHeader: sets the HTTP header of an HTML file.
AppendToLog: Add a string at the end of the Web Server record file.
Clear: Clear HTML output data in the buffer.
End: stop processing asp files and return the current status.
Flush: sends the HTML data of the buffer immediately.

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.