HTML提交方式post和get區別(實驗),postget

來源:互聯網
上載者:User

HTML提交方式post和get區別(實驗),postget
HTML提交方式post和get區別(實驗)一、post和get區別

get提交,提交的資訊都顯示在地址欄中。
post提交,提交的資訊不顯示地址欄中,顯示在訊息體中。

 

二、用戶端代碼
<!DOCTYPE html><html><head><title>Form.html</title><meta name="keywords" content="keyword1,keyword2,keyword3"><meta name="description" content="this is my page"><meta name="content-type" content="text/html; charset=GB2312"><!--<link rel="stylesheet" type="text/css" href="./styles.css">--></head><body>    <!--提交方式:get提交。地址欄:http://localhost:9891/?user=abc&psw=123&repsw=123&sex=nan&tech=java&tech=html&country=cn        GET /?user=abc&psw=123&repsw=123&sex=nan&tech=java&tech=html&country=cn HTTP/1.1Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*Accept-Language: zh-cn,zu;q=0.5Accept-Encoding: gzip, deflateUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; InfoPath.2)Host: localhost:9891Connection: Keep-Alive提交方式:POST地址欄:http://localhost:9891/POST / HTTP/1.1Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*Accept-Language: zh-cn,zu;q=0.5Content-Type: application/x-www-form-urlencodedAccept-Encoding: gzip, deflateUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; InfoPath.2)Host: localhost:9891Content-Length: 68Connection: Keep-AliveCache-Control: no-cacheuser=hahah&psw=8989&repsw=8989&sex=nv&tech=html&tech=css&country=usa                                GET提交和POST提交的區別?        1,        get提交,提交的資訊都顯示在地址欄中。        post提交,提交的資訊不顯示地址欄中。                2,        get提交,對于敏感的資料資訊不安全。        post提交,對于敏感資訊安全。                3,        get提交,對於大資料不行,因為地址欄儲存體積有限。        post提交,可以提交大體積資料。                 4,        get提交,將資訊封裝到了請求訊息的請求行中。        post提交,將資訊封裝到了請求體中。                在服務端的一個區別。        如果出現將中文提交到tomcat伺服器,伺服器預設會用iso8859-1進行解碼會出現亂碼,        通過iso8859-1進行編碼,在用指定的中文碼錶解碼。即可。        這種方式對get提交和post提交都有效。                 但是對於post提交方式提交的中文,還有另一種解決辦法,就是直接使用服務端一個對象        request對象的setCharacterEncoding方法直接設定指定的中文碼錶就可以將中文資料解析出來。        這個方法只對請求體中的資料進行解碼。                         綜上所述:表單提交,建議使用post。                                和服務端互動的三種方式:        1,地址欄輸入url地址。get        2,超連結。 get        3,表單。 get 和  post                        如果在用戶端進行增強型的校正(只要有一個組件內容是錯誤,是無法繼續提交的。只有全對才可以提交)        問,服務端收到資料後,還需要校正嗎?        需要,為了安全性。        為了資訊安全,也為了用戶端那邊不要亂提交資料,用戶端和服務端都需要做校正。                如果服務端做了增強型的校正,用戶端還需要校正嗎?        需要,因為要提高使用者的上網體驗效果,減輕伺服器端的壓力。                        -->    表單格式化    <br>    <!-- action裡面的http協議不能忘記 -->    <form action="http://localhost:9891" method="post">        <!--              cellpadding 屬性規定單元邊沿與其內容之間的空白。             注釋:請勿將該屬性與 cellspacing 屬性相混淆,cellspacing 屬性規定的是單元之間的空間。             從實用角度出發,最好不要規定 cellpadding,而是使用 CSS 來添加內邊距。         -->        <table border="1" bordercolor="#00ffff" cellpadding=10 cellspacing=0            width=400>            <!-- 由此可見,<th>和<td>標籤都是用於表格儲存格顯示的。不同的是<th>在儲存格中加粗顯示。 -->            <tr>                <!-- 佔兩列 -->                <th colspan="2">註冊表單</th>            </tr>            <tr>                <td>使用者名稱稱</td>                <td><input type="text" name="user" value=""><br /></td>            </tr>            <tr>                <td>輸入密碼</td>                <td><input type="password" name="pwd" /><br /></td>            </tr>            <tr>                <td>確認密碼</td>                <td><input type="password" name="repwd" /><br /></td>            </tr>            <tr>                <td>選擇性別</td>                <td><input type="radio" name="sex" value="nan" />男 <input                    type="radio" name="sex" value="nv" checked="checked" />女<br /></td>            </tr>            <tr>                <td>選擇技術</td>                <td><input type="checkbox" name="tech" value="java" />JAVA <input                    type="checkbox" name="tech" value="html" />HTML <input                    type="checkbox" name="tech" value="css" />CSS <br /></td>            </tr>            <tr>                <td>選擇國家</td>                <td><select name="country">                        <option value="none">--選擇國家--</option>                        <option value="usa">美國</option>                        <option value="en">英國</option>                        <!-- 預設選擇中國 -->                        <option value="cn" selected="selected">中國</option>                </select></td>            </tr>            <tr>                <th colspan="2"><input type="reset" value="清除資料" /> <input                    type="submit" value="提交資料" /></th>            </tr>        </table>    </form></body></html>

 

三、伺服器端代碼

RegServer.java

 1 /** 2  *  3  */ 4 package cn.itcast.server; 5  6 import java.io.IOException; 7 import java.io.InputStream; 8 import java.io.PrintWriter; 9 import java.net.ServerSocket;10 import java.net.Socket;11 12 /**13  * @author Fry14  *15  */16 public class RegServer {17 18     /**19      * @param args20      * @throws Exception 21      */22     public static void main(String[] args) throws Exception {23         24         ServerSocket ss = new ServerSocket(9891);//建立服務端連接埠25         26         Socket s = ss.accept();//連接埠監聽27         //輸出伺服器主機地址 ans:0:0:0:0:0:0:0:128         System.out.println(s.getInetAddress().getHostAddress());29         InputStream in = s.getInputStream();//位元組輸入資料流,用來接收用戶端訊息30         byte[] buf = new byte[1024];//1024位元組的緩衝31         int len = in.read(buf);//將收到的訊息讀到buf中32         //輸出接收到的頁面訊息 包括訊息行  訊息頭  訊息體33         System.out.println(new String(buf,0,len));34         //字元輸出,用來儲存發送給用戶端的訊息35         PrintWriter out = new PrintWriter(s.getOutputStream(),true);36         //用戶端接收到的訊息37         out.println("<font color='green' size='7'>註冊成功</font>");38         //關閉連接埠39         s.close();40         ss.close();41     }42 43 }

 

四、結果

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.