Latest web development tutorials

ASP QueryString collection

Request Object Reference Complete Request Object Reference

QueryString collection is used to retrieve the value of the variable in the HTTP query string.

HTTP query string is specified by the value 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 generates a file named txt with the value "this is a query string test" variable.

Query strings are also generated by form submission, or by a user enters a query in the browser address bar.

NOTE: If you need to post large amounts of data (more than 100kb), you can not use Request.QueryString.

grammar

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

参数 描述
variable 必需。在 HTTP 查询字符串中要取回的变量名称。
index 可选。为一个变量规定多个值之一。从 1 到 Request.QueryString(variable).Count。


Examples

Example 1

Traversal query string values ​​of all variables n:

We assumed that this request is sent:

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

The names.asp contains the following code:

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

File names.asp will show:

John
Susan

Example 2

Suppose that the string is 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 the information in the 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 be displayed, such as this:

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

Output will be like this:

Query string is: name=John&age=30


Request Object Reference Complete Request Object Reference