About the order in which the Request object obtains client data in ASP
Source: Internet
Author: User
In ASP, the Request object is a very important object for obtaining data submitted by the client. You are also very familiar with it.
Even so, some people often ask me what are the differences between the following methods and how to write them?
StrMessage = Request ("msg ")
StrMessage = Request. Form ("msg ")
In addition, I have also seen a lot of code written by many people, all of which are in the form of Request (""). Of course there is nothing wrong with such a method.
However, you should note that the Request object has several sets to obtain the data submitted by the client. Generally, QueryString, Form, and ServerVariables are commonly used.
No matter which set can be directly obtained through Request (""), there is a problem here. If the Get method and Post method submit the same variable, for example, if username = cqq, do you use Request ("username") to obtain the obtained data or Post data?
Therefore, when the problem arises, we should have thought that there is a sequence in which requests fetch data from these sets. The order from the front to the back is QueryString, Form, and ServerVariables. The Request object searches for the variables in these sets in order of this order. If there is any matching variable, it will be aborted and the subsequent variables will be ignored.
Therefore, the Request ("username") in the preceding example obtains the data submitted by the Get method.
Therefore, in order to improve efficiency, reduce unnecessary search time, and standardize the program, we recommend that you use the Request. Set method, such as Request. Form ("username ").
The following is a test example. After submission, you can add it directly after the address? Username = test:
<%
If Request ("submit") <> "then
Response. Write "get directly:" & Request ("username") & "<br>"
Response. Write "Get:" & Request. QueryString ("username") & "<br>"
Response. Write "Get Post:" & Request. Form ("username") & "<br>"
End if
%>
<Form name = form1 action = "" method = post>
<Input type = test name = "username" value = "postuser">
<Input type = submit name = "submit" value = "test">
</Form>
From: http://www.contnew.com/tech/develop/asp/2004/10/18_413537_01.html
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