request.form 和 Request.QueryString 區別
ASP.NET 2009-09-02 17:28:20 閱讀243 評論0 字號:大中小
Request從幾個集合取數據是有順序的,從前到後的順序依次是 QueryString,Form,最後是ServerVariables。
Request對象按照這樣的順序依次搜索這幾個集合中的變量,如果有符合的就中止,後面的就不管了。
request.querystring 是用來接收地址裏面?後面的xx=xx的內容
而request.form 是用來接收表單遞交來的數據
不過我可以告訴你個兩全其美的方法
例如 request("offline")
就無論採用的是以上哪種方法的字段值都可以讀取了
B:
request.form是指用form遞交過來的數據。
而request.querystring則是指用URL遞交過來的。你用的是login.asp?offline=true,這個當然是URL遞交的啦。
C:
Request.Form和Request.QueryString兩個接收參數來源不同,
前者是接收從表單Form來的參數,後者是從URL來的參數。
你這有這一句logon.asp?offline=true這是URL的傳遞參數。
如果要用Request.Form()的話,那頁面至少得有個表單,比如:
<form name=form1 method=post action=logon.asp>
<input type=text name=user value="">
</form>
這樣在提交過表單後,就可以用Request.Form("user")得到這個文本框傳遞過來得數值。
D:
request.querystring和request.form的區別
request.querystring是用post方法讀取的 不安全
request.form是用get方法讀取的
form表單中的method中看你是get還是post
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>無標題文檔</title>
</head>
<body>
<p>
<%
if request.querystring("offline")="true" then
session.Abandon()
response.Redirect("login1.htm")
end if
%>
歡迎進入:<%=request.Form("user")%></p>
<p>當前聯機人數爲:</p><%=application("onlinenum")%>
<p><a href=login.asp?offline=true>離開</a></p>
</body>
</html>
Request.Form很明確,就是接收Form提交來的數據。
而Request則會在QueryString、Form、ServerVariable中都搜尋一遍。