Convenient way to parse incoming multipart/form-data parameters in a Servlet [duplicate]
multipart/form-data
encoded requests are indeed not by default supported by the Servlet API prior to version 3.0. The Servlet API parses the parameters by default using application/x-www-form-urlencoded
encoding. When using a different encoding, the request.getParameter()
calls will all return null
. When you're already on Servlet 3.0 (Glassfish 3, Tomcat 7, etc), then you can use HttpServletRequest#getParts()
instead. Also see this blog for extended examples.
Prior to Servlet 3.0, a de facto standard to parse multipart/form-data
requests would be usingApache Commons FileUpload. Just carefully read its User Guide and Frequently Asked Questionssections to learn how to use it. I've posted an answer with a code example before here (it also contains an example targeting Servlet 3.0).
Solutions:
Solution A:
- Download http://www.servlets.com/cos/index.html
- Invoke getParameters() on
com.oreilly.servlet.MultipartRequest
Solution B:
- Download http://jakarta.Apache.org/commons/fileupload/
- Invoke readHeaders() in
org.apache.commons.fileupload.MultipartStream
Solution C:
- Download http://users.boone.net/wbrameld/multipartformdata/
- Invoke getParameter on com.bigfoot.bugar.servlet.http.MultipartFormData
Solution D:
Use Struts. Struts 1.1 handles this automatically.
'java' 카테고리의 다른 글
generate java JNI Header (0) | 2016.08.18 |
---|---|
hashtable vs concurrenthashmap (1) | 2016.08.16 |
hssf vs xssf (0) | 2016.08.10 |
setSoTimeout, connect timeout (0) | 2016.08.05 |
현재 돌고 있는 threadpool 리스트 보기 (0) | 2016.07.04 |