querystring 集合检索 http 查询字符串中变量的值。http 查询字符串由问号 (?) 后的值指定。几个不同的进程都可以生成查询字符串。如,anchor 标记
<a href= "example?string=this is a sample">string sample</a>
生成值为 "this is a sample" 的变量名字符串。通过发送表格或由用户在其浏览器的地址框中键入查询也可以生成查询字符串。
语法
request.querystring(variable)[(index)|.count]
参数
-
variable
-
在 http 查询字符串中指定要检索的变量名。
index
- 这是一个可选参数,可以用来检索 variable 的多个值中的某一个值。这可以是从 1 到 request.querystring(variable).count 之间的任何整数。
注释
querystring 集合是在 servervariables 集合中 query_string 变量的分析版本 。它可以让您以名称检索 query_string 变量。request.querystring (参数) 的值是出现在 query_string 中所有参数 的值的数组。通过调用 request.querystring(parameter).count 可以确定参数有多少个值。如果变量未关联多个数据集,则计数为 1。如果找不到变量,计数为 0。
要在多个数据集合的一个中引用 querystring 变量,请指定 index 的值。index 参数可以是 1 到 request.querystring(variable).count 中任意值。如果没有指定 index 的值,引用多个 querystring 变量中的某个变量时,返回的数据是逗号分隔的字符串。
在 request.querystring 中使用参数时,服务器分析发送给请求的参数,并返回指定的数据。如果应用程序需要未分析的 querystring 数据,可以通过调用不带参数的 request.querystring 检索到这个数据。
可以使用复述符在查询字符串中循环遍历所有的数据值。例如,如果发送以下的请求
http://names.asp?q=fred&q=sally
而且 names.asp 包含下面的脚本,
---names.asp--- <% for each item in request.querystring("q") response.write item & "<br>" next %>
names.asp 将显示如下。
fred sally
上述脚本也可以用 count 来写。
<% for i = 1 to request.querystring("q").count response.write request.querystring("q")(i) & "<br>" next %>
示例
客户端请求
/scripts/directory-lookup.asp?name=fred&age=22
results in the following query_string value.
name=fred&age=22.
querystring 集合将包含 name 和 age两个成员。那么,您就可以使用下面的脚本。
welcome, <%= request.querystring("name") %>. your age is <%= request.querystring("age") %>.
将输出
welcome, fred. your age is 22.
如果使用下面的脚本
the unparsed query string is: <%=request.querystring %>
将输出
the unparsed query string is: name=fred&age=22
应用于
request 对象
