當 HTML 表單使用 method="GET" 提交時,資料會以查詢字串形式附加在 URL 後方(如 tizagGet.asp?Name=John&Age=25)。ASP 透過 Request.QueryString 集合即可取得這些值。
<form method="GET" action="tizagGet.asp">
Name <input type="text" name="Name" />
Age <input type="text" name="Age" />
<input type="submit" />
</form>
<%
Dim name, age
name = Request.QueryString("Name")
age = Request.QueryString("Age")
Response.Write("Name: " & name & "
")
Response.Write("Age: " & age & "
")
%>
Request.QueryString("欄位名稱") 取得字串值,若欄位不存在回傳空字串。Response.CodePage = 65001。<%
' 取得所有查詢字串鍵值
For Each key In Request.QueryString
Response.Write(key & " = " & Request.QueryString(key) & "
")
Next
' 同名多值(如 checkbox 群組)取得陣列
Dim vals : vals = Request.QueryString("colors") ' 回傳 "red,blue,green"
Dim arr : arr = Split(vals, ",")
%>