asp中querystring的用法

本文详细介绍了如何解析HTTP查询字符串中的变量,并通过实例展示了如何在代码中引用和处理这些变量。包括查询字符串的基本概念、语法、参数、示例应用及如何在不同数据集合中引用变量。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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 对象

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值