In ASP, the Request object is a very important object to obtain the data submitted by the client, and everyone is very familiar with it. Despite this, people often ask me what the following writing methods are different and how should I write them?
strMessage = Request("msg")
strMessage = ("msg")
Moreover, I have also seen the code written by many people, all of which are written in Request(""). Of course, there is nothing wrong with this writing.
But everyone should pay attention
The Request object has several collections to obtain the data submitted by the client. Generally, QueryString, Form and ServerVariables are commonly used.
No matter which collection is actually directly obtained 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 data obtained from Get or Post?
So, when the problem comes to this point, you should think that there is a sequence in which Request fetching data from these sets, from front to back
The order is QueryString, Form, and finally ServerVariables. Request objects are searched in this order
If there are any variables in these sets, they will be aborted, and the subsequent variables will be ignored. So the above example Request("username")
What is retrieved is actually the data submitted by the Get method.
Therefore, in order to improve efficiency and reduce unnecessary search time, and also for the specification of the program, it is recommended that you use Request.
A better way, for example ("username").
The following is a test example. After submitting, you can directly add ?username=aaa to the address to test:
<%
If request("submit")<>"" then
"Turn directly: "& Request("username") & "<br>"
"Get:" & ("username") & "<br>"
"Take Post:" & ("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>
strMessage = Request("msg")
strMessage = ("msg")
Moreover, I have also seen the code written by many people, all of which are written in Request(""). Of course, there is nothing wrong with this writing.
But everyone should pay attention
The Request object has several collections to obtain the data submitted by the client. Generally, QueryString, Form and ServerVariables are commonly used.
No matter which collection is actually directly obtained 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 data obtained from Get or Post?
So, when the problem comes to this point, you should think that there is a sequence in which Request fetching data from these sets, from front to back
The order is QueryString, Form, and finally ServerVariables. Request objects are searched in this order
If there are any variables in these sets, they will be aborted, and the subsequent variables will be ignored. So the above example Request("username")
What is retrieved is actually the data submitted by the Get method.
Therefore, in order to improve efficiency and reduce unnecessary search time, and also for the specification of the program, it is recommended that you use Request.
A better way, for example ("username").
The following is a test example. After submitting, you can directly add ?username=aaa to the address to test:
<%
If request("submit")<>"" then
"Turn directly: "& Request("username") & "<br>"
"Get:" & ("username") & "<br>"
"Take Post:" & ("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>