凹丫丫网络社区's Archiver

Amm 发表于 2008-5-15 16:24

ASP和HTML表单 (ASP and HTML Forms)

<FONT size=5><FONT color=#ff0000>在 ASP 中,有两个很常用的集合,一个是 Request.QueryString,另一个是 Request.Form。这两个集合可以获取 HTML 表单(HTML Forms) 提交的信息。<WBR><BR><FONT style="FONT-SIZE: large; LINE-HEIGHT: 1.3em">有关 HTML 表单,请参见 HTML 教程中的 </FONT><WBR></FONT></FONT><A onclick="showLinkBubble(this);return false" href="http://www.blabla.cn/html_tutorials/037_html_form.html" target=_blank link="http://www.blabla.cn/html_tutorials/037_html_form.html"><FONT style="FONT-SIZE: large; LINE-HEIGHT: 1.3em" color=#ff0000>HTML表单 </FONT><WBR></A><WBR><FONT style="FONT-SIZE: large; LINE-HEIGHT: 1.3em" color=#ff0000>一章 。</FONT><WBR><BR><FONT style="FONT-SIZE: large; LINE-HEIGHT: 1.3em" color=#ff0000>Request.QueryStringHTML 表单中的 method 有两种,一种是 get,另外一种是 post。当 HTML 表单的 method="get" 时,可以用 Request.QueryString 来获取表单提交的信息。</FONT><WBR><BR><FONT style="FONT-SIZE: large; LINE-HEIGHT: 1.3em" color=#ff0000>以下是一个让用户输入姓名的 HTML 表单示例。</FONT><WBR><BR><FONT style="FONT-SIZE: large; LINE-HEIGHT: 1.3em" color=#ff0000>&lt;form action="http://www.blabla.cn/asdocs/html_tutorials/yourname.asp " method="get"&gt;</FONT><WBR><BR><FONT style="FONT-SIZE: large; LINE-HEIGHT: 1.3em" color=#ff0000>请输入你的姓名:</FONT><WBR><BR><FONT style="FONT-SIZE: large; LINE-HEIGHT: 1.3em" color=#ff0000>&lt;input type ="text" name="yourname"&gt;</FONT><WBR><BR><FONT style="FONT-SIZE: large; LINE-HEIGHT: 1.3em" color=#ff0000>&lt;input type="submit" value="提交"&gt;</FONT><WBR><BR><FONT style="FONT-SIZE: large; LINE-HEIGHT: 1.3em" color=#ff0000>&lt;/f orm&gt;</FONT><WBR><BR><A onclick="showLinkBubble(this);return false" href="http://www.blabla.cn/html_examples/053_form_input_text.html" target=_blank link="http://www.blabla.cn/html_examples/053_form_input_text.html"><FONT style="FONT-SIZE: large; LINE-HEIGHT: 1.3em" color=#ff0000>演示示例</FONT><WBR></A><WBR><BR><FONT style="FONT-SIZE: large; LINE-HEIGHT: 1.3em" color=#ff0000>该示例中,HTML 表单中使用的 method 为 get ,指向 action 的网页是一个 .asp 文件,名字为 yourname.asp。以下是 yourname.asp 文件的源代码:</FONT><WBR><BR><FONT style="FONT-SIZE: large; LINE-HEIGHT: 1.3em" color=#ff0000>&lt;html&gt;</FONT><WBR><BR><FONT style="FONT-SIZE: large; LINE-HEIGHT: 1.3em" color=#ff0000>&lt;head&gt;</FONT><WBR><BR><FONT style="FONT-SIZE: large; LINE-HEIGHT: 1.3em" color=#ff0000>&lt;title&gt;姓名信息&lt;/title&gt;</FONT><WBR><BR><FONT style="FONT-SIZE: large; LINE-HEIGHT: 1.3em" color=#ff0000>&lt;meta http-equiv ="Content-Type" c&gt;</FONT><WBR><BR><FONT style="FONT-SIZE: large; LINE-HEIGHT: 1.3em" color=#ff0000>&lt;/head&gt;</FONT><WBR><BR><FONT style="FONT-SIZE: large; LINE-HEIGHT: 1.3em" color=#ff0000>&lt;body&gt;</FONT><WBR><BR><FONT style="FONT-SIZE: large; LINE-HEIGHT: 1.3em" color=#ff0000>&lt;p&gt;你的姓名 是:&lt;% = Request.QueryString("yourname") %&gt;&lt;/p &gt;</FONT><WBR><BR><FONT style="FONT-SIZE: large; LINE-HEIGHT: 1.3em" color=#ff0000>&lt;/body&gt;</FONT><WBR><BR><FONT style="FONT-SIZE: large; LINE-HEIGHT: 1.3em" color=#ff0000>&lt;/html&gt;</FONT><WBR><BR><FONT style="FONT-SIZE: large; LINE-HEIGHT: 1.3em" color=#ff0000>在这个 .asp 文件里,你可以看 到最关键的一句代码是:</FONT><WBR><BR><FONT style="FONT-SIZE: large; LINE-HEIGHT: 1.3em" color=#ff0000>&lt;p &gt;你的姓名是:&lt;%= Request.QueryString("yourname") %&gt;&lt;/p&gt;</FONT><WBR><BR><FONT style="FONT-SIZE: large; LINE-HEIGHT: 1.3em" color=#ff0000>Request.QueryString 括号里的 "yourname" 对应于 HTML 表单中的 input 输入框的 name 值。</FONT><WBR><BR><FONT style="FONT-SIZE: large; LINE-HEIGHT: 1.3em" color=#ff0000>HTML 教程中的 HTML表单 一章。提交表单信息时,用户可以从地址栏看到这些提交信息。</FONT><WBR><BR><FONT style="FONT-SIZE: large; LINE-HEIGHT: 1.3em" color=#ff0000>当使用 method="get " 提交表单信息时,用户可以从地址栏看到这些提交信息。</FONT><WBR><BR><FONT style="FONT-SIZE: large; LINE-HEIGHT: 1.3em" color=#ff0000>Request.Form当 HTML 表单中 method = "post" 时,可以用 Request.Form 来获取 HTML 表单提交的信息。</FONT><WBR><BR><FONT style="FONT-SIZE: large; LINE-HEIGHT: 1.3em" color=#ff0000>以下是一个让用户输入姓名和密码的 HTML 表单示例。</FONT><WBR><BR><FONT style="FONT-SIZE: large; LINE-HEIGHT: 1.3em" color=#ff0000>&lt;form action="http://www.blabla.cn/asdocs/html_tutorials/userpw.asp " method ="post "&gt;</FONT><WBR><BR><FONT style="FONT-SIZE: large; LINE-HEIGHT: 1.3em" color=#ff0000>请输入你的姓名:&lt;input type="text" name="yourname"&gt;&lt;br&gt;</FONT><WBR><BR><FONT style="FONT-SIZE: large; LINE-HEIGHT: 1.3em" color=#ff0000>请输入你的密码 :&lt;input type="p assword" name ="yourpw"&gt;&lt;br&gt;</FONT><WBR><BR><FONT style="FONT-SIZE: large; LINE-HEIGHT: 1.3em" color=#ff0000>&lt;input type="submit" value="提交 "&gt;</FONT><WBR><BR><FONT style="FONT-SIZE: large; LINE-HEIGHT: 1.3em" color=#ff0000>&lt;/form&gt;</FONT><WBR><BR><A onclick="showLinkBubble(this);return false" href="http://www.blabla.cn/html_examples/054_form_input_text_password.html" target=_blank link="http://www.blabla.cn/html_examples/054_form_input_text_password.html"><FONT style="FONT-SIZE: large; LINE-HEIGHT: 1.3em" color=#ff0000>演示示例</FONT><WBR></A><WBR><BR><FONT style="FONT-SIZE: large; LINE-HEIGHT: 1.3em" color=#ff0000>该示例中,HTML 表单中使用的 method 为 post,指向 action 的网页是一个 .asp 文件,名字为 userpw.asp。以下是 userpw.asp 文件的源代码:</FONT><WBR><BR><FONT style="FONT-SIZE: large; LINE-HEIGHT: 1.3em" color=#ff0000>&lt;html&gt;</FONT><WBR><BR><FONT style="FONT-SIZE: large; LINE-HEIGHT: 1.3em" color=#ff0000>&lt;head &gt;</FONT><WBR><BR><FONT style="FONT-SIZE: large; LINE-HEIGHT: 1.3em" color=#ff0000>&lt;title&gt;用户信息&lt;/title&gt;</FONT><WBR><BR><FONT style="FONT-SIZE: large; LINE-HEIGHT: 1.3em" color=#ff0000>&lt;meta http-equiv="Content-Type" c&gt;t", ark7); =gb2312"&gt;</FONT><WBR><BR><FONT style="FONT-SIZE: large; LINE-HEIGHT: 1.3em" color=#ff0000>&lt;/head &gt;</FONT><WBR><BR><FONT style="FONT-SIZE: large; LINE-HEIGHT: 1.3em" color=#ff0000>&lt;body&gt;</FONT><WBR><BR><FONT style="FONT-SIZE: large; LINE-HEIGHT: 1.3em" color=#ff0000>&lt;p&gt;你的姓名 是:&lt;% = Request.Form("yourname") %&gt;&lt;/p&gt;</FONT><WBR><BR><FONT style="FONT-SIZE: large; LINE-HEIGHT: 1.3em" color=#ff0000>&lt;p&gt;你的密码是:&lt;%= Request.Form("yourpw") %&gt;&lt;/p&gt;</FONT><WBR><BR><FONT style="FONT-SIZE: large; LINE-HEIGHT: 1.3em" color=#ff0000>&lt;/body &gt;</FONT><WBR><BR><FONT style="FONT-SIZE: large; LINE-HEIGHT: 1.3em" color=#ff0000>&lt;/html&gt;</FONT><WBR><BR><FONT style="FONT-SIZE: large; LINE-HEIGHT: 1.3em" color=#ff0000>在这个 .asp 文件里 ,你可以看到最关键的两句代码是:</FONT><WBR><BR><FONT style="FONT-SIZE: large; LINE-HEIGHT: 1.3em" color=#ff0000>&lt;p&gt;你的姓名是:&lt;%= Request.Form("yourname") %&gt;&lt;/p&gt;</FONT><WBR><BR><FONT style="FONT-SIZE: large; LINE-HEIGHT: 1.3em" color=#ff0000>&lt;p&gt;你的密码是:&lt;%= Request.Form("yourpw ") %&gt;&lt;/p&gt;</FONT><WBR><BR><FONT style="FONT-SIZE: large; LINE-HEIGHT: 1.3em" color=#ff0000>Request.Form 括号里的 "yourname" 和"yourpw " 各对应于 HTML 表单中的两个 input 输入框的 name 值 。</FONT><WBR><BR><FONT style="FONT-SIZE: large; LINE-HEIGHT: 1.3em" color=#ff0000>method 为 post,指向 action 的网页是一个.</FONT><WBR><BR><FONT style="FONT-SIZE: large; LINE-HEIGHT: 1.3em" color=#ff0000>当使用 method="post" 提交表单信息时 ,用户 不会从地址栏看到这些提交信息。</FONT><WBR><BR><FONT style="FONT-SIZE: large; LINE-HEIGHT: 1.3em" color=#ff0000>.Count ,可以得到集合中某个元素的值的总数量。在这个 .asp 。</FONT><WBR><BR><FONT style="FONT-SIZE: large; LINE-HEIGHT: 1.3em" color=#ff0000>HTML表单中还有一些可供用户选择的表单控件,比如单选框 input type="radio",复选框 input type="checkbox",单选下拉框 select,复选下拉框 select multiple。</FONT><WBR><BR><FONT style="FONT-SIZE: large; LINE-HEIGHT: 1.3em" color=#ff0000>这些选择性的控件示例,请参见 </FONT><WBR><A onclick="showLinkBubble(this);return false" href="http://www.blabla.cn/html_tutorials/037_html_form.html" target=_blank link="http://www.blabla.cn/html_tutorials/037_html_form.html"><FONT style="FONT-SIZE: large; LINE-HEIGHT: 1.3em" color=#ff0000>HTML表单教程</FONT><WBR></A><WBR><FONT style="FONT-SIZE: large; LINE-HEIGHT: 1.3em" color=#ff0000> 。在这些示例中,action 指向的那个 .asp 文件叫 choose.asp。以下是 choose.asp 文件的源代码:</FONT><WBR><BR><FONT style="FONT-SIZE: large; LINE-HEIGHT: 1.3em" color=#ff0000>&lt;html&gt;</FONT><WBR><BR><FONT style="FONT-SIZE: large; LINE-HEIGHT: 1.3em" color=#ff0000>&lt;head&gt;</FONT><WBR><BR><FONT style="FONT-SIZE: large; LINE-HEIGHT: 1.3em" color=#ff0000>&lt;title&gt;retrieve inf ormation from form controls (radio, checkbox, select) &lt;/title&gt;</FONT><WBR><BR><FONT style="FONT-SIZE: large; LINE-HEIGHT: 1.3em" color=#ff0000>&lt;meta http-equiv ="Content-Type" c&gt;</FONT><WBR><BR><FONT style="FONT-SIZE: large; LINE-HEIGHT: 1.3em" color=#ff0000>&lt;/head&gt;</FONT><WBR><BR><FONT style="FONT-SIZE: large; LINE-HEIGHT: 1.3em" color=#ff0000>&lt;body &gt;</FONT><WBR><BR><FONT style="FONT-SIZE: large; LINE-HEIGHT: 1.3em" color=#ff0000>你选择了:&lt;br &gt;</FONT><WBR><BR><FONT style="FONT-SIZE: large; LINE-HEIGHT: 1.3em" color=#ff0000>&lt;% For counter = 1 To Request.Form ("fruit").Count</FONT><WBR><BR><FONT style="FONT-SIZE: large; LINE-HEIGHT: 1.3em" color=#ff0000>Response.Write Request.Form("fruit")(counter) &amp; "&lt;br&gt;"</FONT><WBR><BR><FONT style="FONT-SIZE: large; LINE-HEIGHT: 1.3em" color=#ff0000>Next</FONT><WBR><BR><FONT style="FONT-SIZE: large; LINE-HEIGHT: 1.3em" color=#ff0000>%&gt;</FONT><WBR><BR><FONT style="FONT-SIZE: large; LINE-HEIGHT: 1.3em" color=#ff0000>&lt;/body&gt;</FONT><WBR><BR><FONT style="FONT-SIZE: large; LINE-HEIGHT: 1.3em" color=#ff0000>&lt;/html&gt;</FONT><WBR><BR><FONT style="FONT-SIZE: large; LINE-HEIGHT: 1.3em" color=#ff0000>Request.F orm 获取的是一个集合 (collection)。Request.F orm 集合有两个参数,一个是 element ,称做元素,对应 HTML表单控件的 name 值;第二个是 index ,称做索引,表示 element 的第几个值,index 从1开始计数。</FONT><WBR><BR><FONT style="FONT-SIZE: large; LINE-HEIGHT: 1.3em" color=#ff0000>用 Request.Form(element)(index ) 可以引用 Request.F orm 集合中某个元素的某个值。</FONT><WBR><BR><FONT style="FONT-SIZE: large; LINE-HEIGHT: 1.3em" color=#ff0000>比如 Request.Form("fruit")(1),表示 "fruit"元素中的第一个值,Request.Form("fruit")(2) 表示"fruit"元素中的第2个值。</FONT><WBR><BR><FONT style="FONT-SIZE: large; LINE-HEIGHT: 1.3em" color=#ff0000>用 Request.Form(element).Count,可以得 到集合中某个元素的值的总数量。</FONT><WBR><BR><FONT style="FONT-SIZE: large; LINE-HEIGHT: 1.3em" color=#ff0000>比如 Request.Form ("fruit ").Count 为 3 的话,就表示 "fruit" 这个元素有3个值。</FONT><WBR><IMG id=paperPicArea1 style="DISPLAY: none; POSITION: relative" src="http://imgcache.qq.com/ac/qzone_v4/b.gif">

页: [1]

Powered by Discuz! Archiver 7.0.0  © 2001-2007 Comsenz Inc.