Form表單的enctype

基礎form表單

<form action="/submit" enctype="text/plain" method="POST">
    <p>關鍵字: <input type="text" name="keyword" /></p>
    <input type="submit" value="Submit" />
</form>

enctype值和意義

  • application/x-www-form-urlencoded:在發送前編碼全部字符(默認)
  • multipart/form-data:不對字符編碼。在使用包含文件上傳控件的表單時,必須使用該值。
  • text/plain:空格轉換爲 "+" 加號,但不對特殊字符編碼。

說明

HTTP請求中,若是是get請求,那麼表單參數以key1=value1&key2=value2的形式附到url的後面,若是是post請求,那麼表單參數是在請求體中,也是以key1=value1&key2=value2的形式在請求體中。html

post請求的Content-Type爲application/x-www-form-urlencoded,參數是在請求體中,即上面請求中的Form Data。後端servlet能夠經過request.getParameter("keyword")獲取數據git

Content-Type爲text/plain;charset=UTF-8,則請求表單參數在RequestPayload中,後端servlet能夠經過org.apache.commons.io.IOUtils.toString(request.getReader())獲取數據。github

參考

相關文章
相關標籤/搜索