/**
Description: Small issues you need to pay attention to when using the ASP Request object Author: Ci Qinqiang
Email: [email protected]
**/
In ASP, the Request object is a very important object for obtaining data submitted by the client, and everyone is very familiar with it.
Even so, people often ask me what are the differences between the following writing methods and how should they be written?
strMessage = Request("msg")
strMessage = Request.Form("msg")
Moreover, I have seen codes written by many people, and they are all written in the Request("") way. Of course, there is nothing wrong with this way of writing.
But everyone should pay attention
The Request object has several collections to obtain data submitted by the client. The commonly used ones are QueryString, Form and ServerVariables.
No matter what kind of collection, it can be obtained directly through Request(""). There is a problem here. If
Get method and Post method submit the same variable, such as username=cqq, then you use Request("username")
Is the data taken out the data from Get or the data from Post?
So, when the question comes to this point, everyone should think of it. Request takes data from these collections in order. The order from front to back is QueryString, Form, and finally ServerVariables. The Request object searches the variables in these collections in this order. If there is a match, it will stop and the rest will be ignored. So the above example Request("username")
What is actually obtained is the data submitted by the Get method.
Therefore, in order to improve efficiency, reduce unnecessary search time, and also to standardize the program, it is recommended that you use the Request. collection method, such as Request.Form("username").
The following is a test example. After submission, you can directly add ?username=aaa after the address 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>