|
前面我们已经了解如何取得使用者上传的参数值,但那是在已经知道参数名称的状况之下才可以;而使用QueryString 属性我们可以只利用索引来取得参数值,QueryString 属性的型别是NameValueCollection。下面的程序中我们先定义一个NameValueCollection 型态变量来接收QueryString 的内容,然后使用一组巢状循环来取得参数名称及内容: <Html> <Script Language="VB" Runat="Server"> Sub Page_Load(Sender As Object,e As Eventargs) Dim shtLoop1, shtLoop2 As Short Dim arA(), arB() As String Dim colA As NameValueCollection colA=Request.QueryString arA = colA.AllKeys ' 取得全部的键值并存到一个数组中 For shtLoop1 = 0 To UBound(arA) Response.Write("参数名:" & arA(shtLoop1)) arB = colA.GetValues(shtLoop1) ' 利用外循环的索引来取得参数内容并 存到一个数组中 For shtLoop2 = 0 To UBound(arB) Response.Write(" 内容:" & arB(shtLoop2) & "<br>") Next shtLoop2 Next shtLoop1 End Sub </Script> </Html> 由于AllKeys 方法和GetValues 方法的传回值都是数组,所以必须宣告两个数组来接收。我们在网址列输入「http://127.0.0.1/CR/CH09/EX05.aspx?R=1&S=2」后的执行结果,如下图所示: 
| 上网速度更快更爽、更安全下载使用Firefox火狐浏览器
|
|