网络学院 w3pop社区 网络资源 IT新闻

w3pop.com :: 网络学院 :: ASP :: ASP QueryString 集合

会员登陆

帐号

密码

回答

记住密码

忘记密码? 注册

ASP QueryString 集合


作者:w3pop.com 翻译/整理:w3pop.com 发布:2007-04-28 浏览:1327 :: ::

The QueryString collection is used to retrieve the variable values in the HTTP query string.
QueryString集合是用来获取HTTP查询字符串中的变量值的。

The HTTP query string is specified by the values following the question mark (?), like this:
HTTP查询字符串是通过在变量值后面加上一个问号来指定的,如下所示:

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

The line above generates a variable named txt with the value "this is a query string test".
上面这行产生一个变量值为“this is a query string test”的文本。

Query strings are also generated by form submission, or by a user typing a query into the address bar of the browser.
查询字符串也可以通过提交表单产生,或者通过用户浏览器的地址栏中输入查询内容产生,如以上方法。

Syntax
语法

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

Parameter
参数
Description
描述
variable Required. The name of the variable in the HTTP query string to retrieve
必要参数。获取在HTTP查询字符串中的变量名称
index Optional. Specifies one of multiple values for a variable. From 1 to Request.QueryString(variable).Count
可选参数。为一个变量中的多个值指定其中一个。从1开始,一直到Request.QueryString(variable).Count

Examples
举例

Example 1

To loop through all the n variable values in a Query String:

The following request is sent:

http://www.w3schools.com/test/names.asp?n=John&n=Susan

and names.asp contains the following script:

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

The file names.asp would display the following:

John
Susan

Example 2

The following string might be sent:

http://www.w3schools.com/test/names.asp?name=John&age=30

this results in the following QUERY_STRING value:

name=John&age=30

Now we can use the 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 would look like this:

Query string is: name=John&age=30

评论 (0) All