zoukankan      html  css  js  c++  java
  • 客户端表单提交数据方式与服务器获取数据

    表单提交数据的两种方式

           表单form的提交有两种方式,一种是get的方法,通过超级链接后面的参数提交过来,一种是post ,通过Form表单提交过来。

    post方式:

    <form id="form1" name="form1" method="post" action="login.aspx">
      <table width="501" border="0" align="center" id="." class="borderStyele">
        <tr>
          <td width="164" align="right">用户名:</td>
          <td width="326" align="left"><label>
          <input type="text" name="userName" />
          </label></td>
        </tr>
        <tr>
          <td align="right">密码:</td>
          <td align="left"><label>
            <input type="password" name="userPwd" />
          </label></td>
        </tr>
        <tr>
          <td colspan="2" align="center"><label>
            <input type="submit" name="Submit" value="提交" />  
            <input type="reset" name="Submit2" value="重置" />
          </label></td>
        </tr>
      </table>
    </form>

    get方式:

    <form id="form1" name="form1" method="Get" action="login.aspx">
      <table width="501" border="0" align="center" id="." class="borderStyele">
        <tr>
          <td width="164" align="right">用户名:</td>
          <td width="326" align="left"><label>
          <input type="text" name="userName" />
          </label></td>
        </tr>
        <tr>
          <td align="right">密码:</td>
          <td align="left"><label>
            <input type="password" name="userPwd" />
          </label></td>
        </tr>
        <tr>
          <td colspan="2" align="center"><label>
            <input type="submit" name="Submit" value="提交" />  
            <input type="reset" name="Submit2" value="重置" />
          </label></td>
        </tr>
      </table>
    </form>

    post 和 get 的区别:

               a.最明显的一点是,get提交方式,所提交过程传输的数据会显示在地址栏里面,而post不会.

         b.get的提交方式一般用于比较少的数据提交,而post用于比较多、大的数据传输.

         c.get的提交方式所提交的数据,在服务器上是不需要保存的,而post的提交方式提交的数据服务器会永久保存.

         d.get方法是通过uRL传递数据给程序的,数据容量小并且数据暴露在url中非常不安全,post方法能传输大容量的数据并且所有操作对用户来说都是不可见的,非常安全。

    表单form提交数据与Request的联系

              Request对象的属性和方法比较多,常用的几个为:UserAgent 传回客户端浏览器的版本信息,UserHostAddress 传回远方客户端机器的主机IP地址,UserHostName 传回远方客户端机器的DNS 名称,PhysicalApplicationPath 传回目前请求网页在Server端的真实路径。

    客户端提交数据后需要通过Request内置对象在服务端获取数据。

        Request对象功能是从客户端得到数据,常用的三种取得数据的方法是:Request.Form.Get("username")Request.QueryString("username")Request["username"]。其第三种是前两种的一个缩写,可以取代前两种情况。而前两种主要对应的Form提交时的两种不同的提交方法:分别是Post方法和Get方法。即当表单中的method的值为Get时,在后台服务器中获取数据的方法可以为Request.QueryString("username")Request["username"],当method的值为Post时在后台服务器中获取数据的方法为Request.Form.Get("username")或Request["username"]。

    Post:

    string username=Request.Form.Get("username");
    string password = Request.Form.Get("password");

    Get:

    string username = Request.QueryString["username"].ToString();
    string password=Request.QueryString["password"].ToString();

    Get、Post都适用:

    string username = Request["username"].ToString();
    string password=Request["password"].ToString ();
  • 相关阅读:
    20188477 编程作业
    原型设计
    案例分析
    编程作业
    阅读任务
    准备工作
    原型设计作业
    案例分析作业
    编程作业
    阅读任务
  • 原文地址:https://www.cnblogs.com/sunran/p/3851188.html
Copyright © 2011-2022 走看看