The order in which the request object obtains client data in ASP (easy to ignore)

Source: Internet
Author: User
Tags servervariables

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 many people writeCodeAll requests ("") are written. Of course, there is nothing wrong with such writing.
But 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.
However, no matter which set you want to obtain directly through request (""), there is a problem here.
The get method and post method submit the same variable, such as username = cqq, then you use request ("username ")
Is the obtained data obtained from get or post?

Therefore, when the problem arises, we should have thought that there is a sequence in which requests retrieve data from these sets, from the beginning to the end.
The order is querystring, form, and servervariables. The request object is searched in this order.
The variables in these sets will be aborted if any matching variable exists, and the subsequent variables will be ignored. Therefore, the above example request ("username ")
The actual data obtained is the data submitted by the get method.

Therefore, to improve efficiency, reduce unnecessary search time, andProgramWe recommend that you use the request. Set
The method is better, for example, request. Form ("username ").

The following is a test example. After submission, you can add it directly after the address? Username = aaa to 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>

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.