ASP在动态网页中提供了多种页面间传递变量的方法.
方法1:利用表单的GET方法,然后在下一页中用Request.querystring 法获得表单中元素的值.例如: FILE1 : sending.asp <form name="sending" method="GET" action="getting.asp" target="_self"> </FONT><font size="2">Name :</font><br> <input name="name" size="22" > <br> <font size="2">Phone:</font><br> <input name="phone" size="14" > <br> <input type="submit" value="Send" name="Send"> </form> FILE2 : getting.asp <% dim gotname,gotphone gotname = Request.querystring("name") gotphone = Request.querystring("phone") %>
方法2:利用表单的POST方法,然后在下一页中用Request.Form方法获得表单中元素的值.例如:
FILE1 : sending.asp <form name="sending" method="POST" action="getting.asp" target="_self"> </FONT><font size="2">Name :</font><br> <input name="name" size="22" > <br> <font size="2">Phone:</font><br> <input name="phone" size="14" > <br> <input type="submit" value="Send" name="Send"> </form>
FILE2 : getting.asp <% dim gotname,gotphone gotname = Request.Form("name") gotphone = Request. Form("phone") %>
方法3:在超链接中直接输入变量的值,然后在下一个页面中用request.querystring直接获得它的值,例如 :
FILE1 : sending.asp <% name = "jin ruimin" phone = "86528779" %> <a href="getting.asp?name=<%=name%>&phone=<%=phone%>" target="_self" ></a>
FILE2 : getting.asp <% gotname = request.querystring("name") gotphone = request.querystring("phone") %>
方法4:利用session变量来保存值,然后在后面的无论哪个页面中都可以直接提取该变量的值,例如 :
FILE1 : sending.asp <% session("name") = "jin ruimin" session("phone") = "86528779" %>
FILE2 : getting.asp <% gotname = session("name") gotphone = session("phone") %>
方法5:与session变量类似,用response.cookies把值保存cookies变量中,然后在后面的无论哪个页面中都可以种用request.cookies来获得该值,例如:
FILE1 : sending.asp <% response.cookies("name") = "jin ruimin" response.cookies("phone") = "86528779" %>
FILE2 : getting.asp <% gotname = request.cookies("name") gotphone = request.cookies("phone") %>
方法6:利用表单元素中的隐藏域来传递变量,如果不想在网页中显示出表单,而在下一个页面中利用 request.Form获得值.例如:
FILE1 : sending.asp <form name="sending" method="post" action="getting.asp"> <input type="hidden" name="name" value="jin ruimin"> <input type="hidden" name="phone" value=" 86528779" > </form>
FILE2 : getting.asp <% gotname = Request.Form("name") gotphone = Request.Form ("phone") %> |