Learn more about ASP built-in objects request

Source: Internet
Author: User
Tags html page http request query servervariables port number

System learning ASP, is first from the ASP's several large built-in objects started. Generally called Five objects: Request, Response, Server, Session, application. Today, let's look at the request object.

Of course, has not been mentioned is, what is the ASP in the end? How do I know the code is ASP code? Very simple, when you see "<%" and "%>" on the show is ASP, and between the two is the ASP source.

Then why to learn the object, the role of the object is how?

In fact, the ASP provides these built-in objects that can be used in the script, making it easier for users to collect information sent through a browser request, respond to browsers, and store user information, thus getting the object developer out of a lot of tedious work.

The main function of the request object is to accept the information from the client browser and submit or upload it on the server side. The Request object can access any information that is delivered based on an HTTP request, including parameters, cookies, and so on that are passed from the form table using the POST method or the Get method.

One, Request.Form ("name")

This is an acceptable way to accept the information from the previous page. The request is an ASP object, and the form is a collection of objects contained in the request object (which is different from the form forms in the HTML page), which is the name of a text box, password box, or hidden field in the previous page's form. And it's also important: The Submit method for the previous form form must be the POST method.

Say better do, look at the following two page programs.

1,test1.html (This page is HTML, mainly provides a platform for input information to submit information to the following 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>

Note that method is post, and the submitted page action is submit1.asp.

2,submit1.asp (ASP page, which takes two values from test1.html name= "yourname" and Name= "Yourpwd")

Your name Is:<%=request.form ("Yourname")%><br>
Your pwd is:<%=request.form ("yourpwd")%>

With IIS for the HTTP protocol page debugging, you will find two pages are associated: test1.html in the dynamic input of the name and PWD, in the submit1.asp is also the corresponding dynamic display.
This is the whole process of receiving, extracting, and displaying information.

3, improved submit1.asp

<% for all I in request.form%>
<%=i%>:
<%=request.form (i)%>
<br>
<%next%>

The FOR Loop statement is used to accept and display all form label information on the previous page. This comes out very quickly when there are many items on the form page.

The first is still request.form, just the Back ("Yourname") or ("Yourpwd") becomes the variable i

Through the For loop to the form collection traversal extraction, this is a different from the mechanical "there are several on the extraction of several" programming ideas, attention to grasp.

Two, Request.QueryString ("name")

At this time from Request.Form to Request.QueryString, the most important or the previous page to submit the form, the use of what method. Use Request.Form when using a post, otherwise use request.querystring when using get.

What's the biggest feature of Request.QueryString? Request.QueryString can retrieve and accept the value of a variable in an HTTP query string, and the HTTP query string is specified by the value after the question mark (?). For half a day, keep looking at a program.

1,test2.html (This page is HTML, mainly provides a platform for input information to submit information to the following ASP page for processing, note that the submission method is get)

<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 with test1.html is method= "get."

2,submit2.asp (ASP page, which takes two values from test1.html name= "yourname" and Name= "Yourpwd")

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

Note that the browser address bar at this time, the file behind more? Number,? The variable name followed by the assigned value, and of course the number of variable names are connected by &.

And the biggest function of request.querystring is to be able to The variable names that follow the number are separated and the corresponding values are removed.

Just now said that the different variable names are connected with the & number, but if the same variable name, request.querystring in the end is to extract the previous one? The latter one? Or the two together?
Use an example to speak.

3,query.asp (name is query.asp, because in the page program is feedback to yourself.) )

<a href= "query.asp?bookname= asp Tutorials" > "ASP Tutorials" </a><br>
<a href= "query.asp?bookname= jsp Tutorial" > "JSP Tutorial" </a><br>
<a href= "query.asp?bookname= xsp Tutorial" &bookname= "xml" > "XSP Course" </a><br>
You chosed <%=request.querystring ("BookName")%>

Obviously when the xSP tutorial, it shows "xSP tutorial", "xml", the middle automatically added "," number.

Finally, it is still necessary to note that Request.QueryString is often used in the paging program.

Three, Request.ServerVariables ("xxx")

Where ServerVariables is the server environment variable, the variable contains more content, we also use for loop to traverse the view.

1,server1.asp

<%for each i in request.servervariables%>
<%=i%>:
<%=request.servervariables (i)%>
<%Next%>

Can see a lot of environment variables, which have no value, the following pick a few more commonly used.

Http_user_agent (client machine related environment): <%=request.servervariables ("Http_user_agent")%><br>
Http_accept_language (Browse language): <%=request.servervariables ("Http_accept_language")%><br>
Content_length (length of client-issued content): <%=request.servervariables ("Content_length")%><br>
Content_Type (the data type of the content.) such as "text/html". Used with queries with additional information, such as HTTP query get, POST, and put: <%=request.servervariables ("Content_Type")%><br>
LOCAL_ADDR (returns the server address that accepts the request.) This variable is important if the address used by the request is found on a multihomed machine that binds multiple IP addresses: <%=request.servervariables ("local_addr")%><br>
REMOTE_ADDR (the IP address of the remote host client that issued the request): <%=request.servervariables ("REMOTE_ADDR")%><br>
SERVER_NAME (server host name, DNS alias, or IP address that appears in the self-referencing URL): <%=request.servervariables ("SERVER_NAME")%><br>
Script_name (virtual address after host name): <%=request.servervariables ("Script_name")%><br>
Logon_User (User login to Windows NT account): <%=request.servervariables ("LOGON_USER")%><br>
Server_port (port number to send request): <%=request.servervariables ("Server_port")%>

According to the above server_name is the extraction of the server host name, Script_name is extracted virtual address, then the combination of the two plus http://is not a complete URL.

2,server2.asp

<%a=request.servervariables ("SERVER_NAME")%>
<%b=request.servervariables ("Script_name")%>
<%= "http://" &a&b%>

where http://in quotation marks, the expression is a string, a and B are corresponding to the specific value of the variable, in the ASP to do such a connection is to use the & number.

Based on this result, we will be able to extract the dynamic URL address at any time.

Look at the query.asp, the request must be saved as query.asp, because if not the file name, the program points to an error.

But now this file is as easy as you save why file, all the same execution.

3,xxx.asp (whatever file you want to save)

<%filepath=request.servervariables ("Script_name")%>
<a href= "<%=filepath%>?bookname= asp Tutorials" > "ASP Tutorials" </a><br>
<a href= "<%=filepath%>?bookname= jsp Tutorial" > "JSP Tutorial" </a><br>
<a href= "<%=filepath%>?bookname= xsp Tutorial" &bookname= "xml" > "XSP Course" </a><br>
You chosed <%=request.querystring ("BookName")%>

Take the address of the current file and assign it to the variable filepath, and then all the link addresses begin by simply referencing the variable. is not very useful, a little omnipotent feeling.

Four, Request.Cookies ("name")

Needless to say, cookies are a very important thing, exactly how, after we have learned the following objects response.

The above four applies to the collection of four objects contained in the Request object: Form, QueryString, Servervarivables, cookies. Of course, there's a clientcertificate.

An ASP Built-in object has object properties, object methods in addition to the collection of objects

The object property of the request object is only one totalbytes (the number of bytes accepted), you can

<%=request.totalbytes%>

The statement is added to any ASP page that accepts data.

The object method of the request object is also one: BinaryRead.
To tell the truth, this stuff is not commonly used, I have no use, hehe.

ok~! About the Request object of study is almost, the most important thing is to understand the collection of three objects, cookies do not worry, the next section of learning 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.