http協議的請求方法get和post的區別
* get和post的使用時機:
* 何時使用get請求方法
* 在地址欄直接寫訪問的路徑 此時請求方法是get
* 使用超鏈接 此時請求方法是get
* 當form表單的屬性method=get時,請求方法是get
* 何時使用post請求方法
* 當form表單的屬性method=post時,請求方法是post
* 從傳輸的數量來看
* 使用get請求方法,傳遞的數據量少
* 使用post請求方法,可以傳遞大的數據量
* 地址欄的變化:
* 請求方法是get,在地址欄可以看到傳遞的表單信息
http://localhost:8080/myAppServlet/methodServlet?username=zhang&tel=1234
*請求方法是post,在地址欄不可以看到傳遞的表單信息
http://localhost:8080/myAppServlet/methodServlet
////////////////////////////////////////////////////////////////////////////////////////
get和post在url後參數傳遞的方式:
* 傳遞參數的格式如下
Http://locahost:808/xxxxx/xxxxservlet?參數的名稱1=參數的值1
Http://locahost:808/xxxxx/xxxxservlet?參數的名稱1=參數的值1&參數的名稱2=參數的值2&參數的名稱3=參數的值3
* get鏈接方式:
<a href="./methodServlet?a=9&b=abc">testgetparams</a>
* get方式 表單請求方法是get時 後不能給參數,可以採用隱藏域的方式
<form action="./methodServlet" method="get">
<input type="hidden" name="a" value="123">
用戶名:<input type="text" name="username"><br>
密碼:<input type="text" name="tel" value="1234"><br>
<input type="submit" value="提交">
</form>
* post表單提交的方式:
<form action="./methodServlet?a=67&b=ooooo" method="post">
用戶名:<input type="text" name="username"><br>
電話:<input type="text" name="tel" value="1234"><br>
<input type="submit" value="保存">
</form>
http協議的請求方法get和post的區別
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.