You're mixing Apache Commons FileUpload and Servlet 3.0 @MultipartConfig
. Those two are entirely distinct ways to parse multipart/form-data
requests. A HTTP request can be parsed only once. So if one of those two ways has already parsed it beforehand, the other way would not be able to parse it anymore and end up with null/empty data.
You should use the one or the other way to parse the request and not both ways. Apache Commons FileUpload was the "de facto" standard to parse multipart/form-data
requests before Servlet 3.0 was introduced (Dec 2009). But since Servlet 3.0 there's the new @MultipartConfig
annotation and the new request.getPart()
method which makes Apache Commons FileUpload superfluous.
When using Apache Commons FileUpload, you should remove the Servlet 3.0 @MultipartConfig
and all request.getParameter()
lines and extract the "regular" request parameters from the List items
instead.
When using Servlet 3.0 @MultipartConfig
, you should remove all code related to Apache Commons FileUpload and use request.getPart()
instead to obtain the uploaded file.
See also: