Go to ASP programming advanced (4): built-in Object Request

Source: Internet
Author: User
Tags servervariables

System learning ASP begins with several built-in ASP objects.
Five objects are generally called:Request, response, server, session, Application
Let's take a look at the request object today.

Of course, what has not been mentioned yet is what ASP is like? How do I know the code is ASP code?
When "<%" and "%>" are displayed, ASP is used, and ASP source code is used between the two.

So why is the role of the object to be learned?
In fact, ASP provides these built-in objects that can be used in scripts, making it easier for users to collect information sent through browser requests, respond to browsers, and store user information, this frees object developers from a lot of tedious work.

The main function of the request object is to receive and obtain information submitted or uploaded from the client browser on the server side. The request object can access all information transmitted Based on HTTP requests, including parameters and cookies transmitted from the form using the POST method or get method.

1. Request. Form ("name ")

This is an acceptance method that is often used to accept information on the previous page. Request is an ASP object, and form is the set of objects contained in the request object (the difference is different from the form in the HTML page ), name is the name of a text box, password box, or hidden field in the previous page form. It is also very important that the method for submitting the form on the previous page must be the POST method.
Let's look at the two page programs below.

1. test1.html (this page is HTML and mainly provides a platform for inputting information to submit the information to the next ASP page for processing)

<Form action = "submit1.asp" method = "Post">
Your name: <input tpye = "text" name = "yourname"> <br>
Your PWD: <input type = "password" name = "yourpwd"> <br>
<Input type = "Submit" value = "Submit">
</Form>

2. submit1.asp(asp page, and the following two values are accepted from test1.html: Name = "yourname" and name = "yourpwd)

Your name is: <% = request. Form ("yourname") %> <br>
Your PWD is: <% = request. Form ("yourpwd") %>

When you debug HTTP pages through IIS, you will find two pages are associated: the name and PWD dynamically entered in test1.html, and the corresponding dynamic display is also performed in submit1.asp.
This is the entire process of receiving, extracting, and displaying information.

3. Improved submit1.asp

<% For each I in request. Form %>
<% = I %>:
<% = Request. form (I) %>
<Br>
<% Next %>

The for loop statement is used to accept and display all form tag information on the previous page. This results quickly when there are many projects on the single page of the table above.
Request. form, but the variable ("yourname") or ("yourpwd") is changedI
The for loop is used to traverse and extract the form set. This is a programming idea different from the mechanical method of "extracting just a few.

2. Request. querystring ("name ")

At this time, the change from request. Form to request. querystring is mainly about the method used when the previous form is submitted. If post is used, request. form is used; otherwise, request. querystring is used when get is used.

What are the biggest features of request. querystring? Request. querystring can retrieve and accept the value of the variable in the HTTP query string, while the HTTP query string is composed of question marks (?) The value after. After talking about it for a long time, I will continue to read a program.

1. test2.html (this page is the same as HTML and mainly provides a platform for inputting information to submit the information to the next ASP page for processing. Note that the submission method is get)
Run code box

<Form action = "submit2.asp" method = "get">
Your name: <input tpye = "text" name = "yourname"> <br>
Your PWD: <input type = "password" name = "yourpwd"> <br>
<Input type = "Submit" value = "Submit">
</Form>

The biggest difference between test1.html and method = "get"

2. submit2.asp(asppage, and the following two values are accepted from test1.html: Name = "yourname" and name = "yourpwd)

Your name is: <% = request. querystring ("yourname") %> <br>
Your PWD is: <% = request. querystring ("yourpwd") %>

Note that there are more files in the browser address bar? ,? Variable names and assigned values are attached to the variable names. Of course, multiple variable names are connected by the & sign.
What is the biggest function of request. querystring? The names of these variables are separated, and the corresponding values are also taken out one by one.

We just mentioned that different variable names are connected with the & sign. But if the same variable name is used, is request. querystring the first one extracted? Next? Or two together?
Use an example.
3. query. asp (the name is query. asp, because it is reported to you in this page program .)

<A href = "query. asp? Bookname = ASP tutorial "> Asp tutorial </a> <br>
<A href = "query. asp? Bookname = jsp tutorial "> JSP tutorial </a> <br>
<A href = "query. asp? Bookname = xsp tutorial & bookname = xml "> xsp tutorial </a> <br>
You chosed <% = request. querystring ("bookname") %>

Obviously, when you click "xsp tutorial", "xsp tutorial" and "XML" are displayed. "," is automatically added in the middle.
 
It should be noted that request. querystring is frequently used in paging programs. ImageHttp://www.cnbruce.com/database/

3. Request. servervariables ("XXX ")
Among them, servervariables is the environment variable of the server. This variable contains a lot of content. We also use the for loop to traverse and view it.
1, server1.asp

<% For each I in request. servervariables %>
<% = I %>:
<% = Request. servervariables (I) %>
<HR>
<% Next %>

We can see a lot of environment variables, but there are still no values. The following are some of the more common ones.

Http_user_agent (related environment of the client machine): <% = request. servervariables ("http_user_agent") %> <br>

Http_accept_language (Browser language): <% = request. servervariables ("http_accept_language") %> <br>

Content_length (length of the content sent by the client): <% = request. servervariables ("content_length") %> <br>

Content_type (the data type of the content. For example, text/html ". Used together with the query of additional information, such as HTTP query get, post, and put): <% = request. servervariables ("content_type") %> <br>

Local_addr (returns the server address that receives the request. This variable is very important if you look for the address used by the request on multiple host machines bound to multiple IP addresses): <% = request. servervariables ("local_addr") %> <br>

Remote_addr (IP address of the remote host client sending the request): <% = request. servervariables ("remote_addr") %> <br>

SERVER_NAME: <% = request. servervariables ("SERVER_NAME") %> <br>

Script_name (virtual address after the Host Name): <% = request. servervariables ("script_name") %> <br>

Logon_user (account used to log on to Windows NT): <% = request. servervariables ("logon_user") %> <br>

Server_port (the port number for sending the request): <% = request. servervariables ("server_port") %>


According to the above SERVER_NAME is the extracted server host name, script_name is the extracted virtual address, then the combination of the two plusHttp ://Is it a complete website.
2, server2.asp

<% A = request. servervariables ("SERVER_NAME") %>
<% B = request. servervariables ("script_name") %>
<% = "Http: //" & A & B %>

WhereHttp ://Enclosed by quotation marks, it is a string. A and B are the variables corresponding to specific values. In ASP, such a connection uses the & sign.

Based on this result, can we extract dynamic URLs at any time.

Let's take a look at query. asp, which must be saved as query. asp, because if it is not the file name, an error occurs when the program points to it.
However, the current file is executed in the same way as the files you save.
3, XXX. asp (whatever file you save)

<% Filepath = request. servervariables ("script_name") %>
<A href = "<% = filepath %>? Bookname = ASP tutorial "> Asp tutorial </a> <br>
<A href = "<% = filepath %>? Bookname = jsp tutorial "> JSP tutorial </a> <br>
<A href = "<% = filepath %>? Bookname = xsp tutorial & bookname = xml "> xsp tutorial </a> <br>
You chosed <% = request. querystring ("bookname") %>

First, extract the address of the current file and assign it to the variable filepath.
Then, it is okay to directly reference the variable at the beginning of all the link addresses.
Is it useful? It's a bit omnipotent.

4. Request. Cookies ("name ")
I don't need to say that cookie is a very important thing. What should we do? After we finish learning the following object response, we will have a special cookie lecture.
Let's put it aside first.

The preceding four examples use the form, querystring, servervarivables, and cookies contained in the request object.Of course there is another clientcertificate.

An ASP built-in object besidesObject setBesidesObject Attributes,Object Method

Request objectObject AttributesOnly one is totalbytes (number of accepted bytes). You can set

<% = Request. totalbytes %>

This statement is displayed on any ASP page that accepts data.

Request objectObject MethodOr binaryread.
To be honest, this stuff is not commonly used, and I have never used it.

OK ~! The learning of the request object is almost the same. The most important thing is to have a good understanding of the three object sets. Cookies are not in a hurry. The next section will continue to learn the object response.



Related Article

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.