ASP QueryStringCollection


Request 对象参考手册Complete Request Object Reference

The QueryString collection is used to retrieve the values of variables in the HTTP query string.

The HTTP query string is specified by the values after the question mark (?), for example:

<a href= "test.html?txt=this is a query string test">Link with a query string</a>

The above code can generate a variable named txt with the value "this is a query string test".

The query string can also be generated by form submission, or by the user entering a query in the browser's address bar.

Note:If you need to POST a large amount of data (over 100kb), you cannot use Request.QueryString.

Syntax

Request.QueryString(variable)[(index)|.Count]

Parameter Description
variable Required. The name of the variable to retrieve from the HTTP query string.
index Optional. Specifies one of multiple values for a variable. From 1 to Request.QueryString(variable).Count.


Examples

Example 1

Loop through the values of all variable n in the query string:

Assume this is the request being sent:

http://www.w3cschool.cc/test/names.html?n=John&n=Susan

And names.asp contains the following code:

<%
for i=1 to Request.QueryString("n").Count
  Response.Write(Request.QueryString("n")(i) & "<br>")
next
%>

The file names.asp will display:

John
Susan

Example 2

Assume this is the string being sent:

http://www.w3cschool.cc/test/names.html?name=John&age=30

The above code produces the following QUERY_STRING value:

name=John&age=30

Now, we can use this information in a script:

Hi, <%=Request.QueryString("name")%>. 
Your age is <%= Request.QueryString("age")%>.

Output:

Hi, John. Your age is 30.

If you do not specify any variable values to display, like this:

Query string is: <%=Request.QueryString%> 

The output will become like this:

Query string is: name=John&age=30


Request 对象参考手册Complete Request Object Reference Other Extensions