Introduction to ASP Programming (IV): built-in object request

Source: Internet
Author: User
Tags html page http request modify query servervariables client
Request| Programming | object | Built-in object system learning ASP, is first from the ASP's several large built-in objects started.
Generally called the five main 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>
[Ctrl + A ALL SELECT hint: You can modify some of the code, and then run]

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>
[Ctrl + A ALL SELECT hint: You can modify some of the code, and then run]

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. Like http://www.cnbruce.com/database/

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 (return to accept request



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.