Request 對象之QueryString集合

來源:互聯網
上載者:User

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 將顯示如下。

FredSally

上述指令碼也可以用 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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.