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>