request.getParameter()、request.getInputStream()和request.getReader()

enctype=application/x-www-form-urlencoded get方式php

內容部分:title=test&content=%B3%AC%BC%B6%C5%AE%C9%FA&submit=post+articlespring

讀取數據: request.getParameter() 由於按流讀取後數據後,其餘方法讀不到數據。mvc

enctype=multipart/form-data post方式app

內容部分:post

POST /post_test.php?t=1 HTTP/1.1  
Accept-Language: zh-CN  
User-Agent: Mozilla/4.0    
Content-Type: multipart/form-data; boundary=---------------------------7dbf514701e8  
Accept-Encoding: gzip, deflate  
Host: 192.168.12.102  
Content-Length: 345  
Connection: Keep-Alive  
Cache-Control: no-cache  
   
-----------------------------7dbf514701e8  
Content-Disposition: form-data; name="title"  
test  
-----------------------------7dbf514701e8  
Content-Disposition: form-data; name="content"  
....  
-----------------------------7dbf514701e8  
Content-Disposition: form-data; name="submit"  
post article  
-----------------------------7dbf514701e8--

Content-Type中定義boundary在內容中用到。url

讀取數據:request.getParameter() 讀不到數據,request.getInputStream()和request.getReader() 在同一個request中混合使用會拋出異常。code

springmvc 中 CommonsMultipartResolver.resolveMultipart(HttpServletRequest request) 完成了對兩種狀況的遞交數據的解析,使咱們方便的獲取參數而不用有太多顧及。orm

相關文章
相關標籤/搜索