当前位置: 首页 > 网络学院 > 服务端脚本教程 > ASP > ASP QueryString 集合

ASP
ASP 介绍
ASP Install
ASP 语法
ASP 变量
ASP Procedures
ASP Forms
ASP Cookies
ASP Session
ASP Application
ASP #include
ASP Global.asa
ASP Send e-mail
ASP Response
ASP Request
ASP Application
ASP Session
ASP Server
ASP Error
ASP FileSystem
ASP TextStream

ASP QueryString 集合


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-04   浏览: 413 ::
收藏到网摘: n/a

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

登陆 | 还没注册?