본문 바로가기

java

multipart/form-data 자바에서 받는 여러가지 선택지! file upload

Convenient way to parse incoming multipart/form-data parameters in a Servlet [duplicate]



first Answer

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 3Tomcat 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).




second Answer

Solutions:

Solution A:

  1. Download http://www.servlets.com/cos/index.html
  2. Invoke getParameters() on com.oreilly.servlet.MultipartRequest

Solution B:

  1. Download http://jakarta.Apache.org/commons/fileupload/
  2. Invoke readHeaders() in org.apache.commons.fileupload.MultipartStream

Solution C:

  1. Download http://users.boone.net/wbrameld/multipartformdata/
  2. Invoke getParameter on com.bigfoot.bugar.servlet.http.MultipartFormData

Solution D:

Use Struts. Struts 1.1 handles this automatically.

Reference: http://www.jguru.com/faq/view.jsp?EID=1045507






'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