您的位置:首页 > 产品设计 > UI/UE

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

2017-09-13 00:00 489 查看
enctype=application/x-www-form-urlencoded get方式

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

读取数据: request.getParameter() 因为按流读取后数据后,其他方法读不到数据。

enctype=multipart/form-data 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在内容中用到。

读取数据:request.getParameter() 读不到数据,request.getInputStream()和request.getReader() 在同一个request中混合使用会抛出异常。

springmvc 中 CommonsMultipartResolver.resolveMultipart(HttpServletRequest request) 完成了对两种情况的递交数据的解析,使我们方便的获取参数而不用有太多顾及。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ServletRequest
相关文章推荐