java servlet无法处理multipart/form-data导致request.getParameter()返回null

o

image.png

经过反复测试排查,才确认,servlet无法使用request.getParameter()读取使用multipart/form-data发送的数据。

request.getParameter()只能读取使用application/x-www-form-urlencoded发送的数据。

两者报文格式分别如下:


1、application/x-www-form-urlencoded:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

POST /xxxyyy HTTP/1.1

Host: 192.168.1.1:8080

Connection: keep-alive

Content-Length: 75

Cache-Control: max-age=0

Upgrade-Insecure-Requests: 1

Content-Type: application/x-www-form-urlencoded


username=zhangsan&location=9&sax=male

(此处无换行)


2、multipart/form-data:

~~~~~~~~~~~~~~~~~~~~~

POST /xxyyzz HTTP/1.1

Host: 192.168.1.1:8080

Connection: keep-alive

Content-Length: 43164

Cache-Control: max-age=0

Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryEd5vCC6bFMXXvNC7


------WebKitFormBoundaryEd5vCC6bFMXXvNC7

Content-Disposition: form-data; name="usernam"


zhangsan

------WebKitFormBoundaryEd5vCC6bFMXXvNC7

Content-Disposition: form-data; name="location"


9

------WebKitFormBoundaryEd5vCC6bFMXXvNC7

Content-Disposition: form-data; name="sex"


male

------WebKitFormBoundaryEd5vCC6bFMXXvNC7

Content-Disposition: form-data; name="filen"; filename="testf.jpg"

Content-Type: image/jpeg


此处文件二进制数据

------WebKitFormBoundaryEd5vCC6bFMXXvNC7--



(点击率:1049)

评论

昵称

 聚享站 | 培训学校管理系统 | 惊觉社区 | 杭州同城分类信息 | 
这视界--www.deepvast.com这视界

浙ICP备17017888号