Most web applications require multipart file upload functionality. Spring MVC makes it extremely easy to handle this otherwise cumbersome feature. It provides two built-in implementations of MultiPartResolvers
: CommonsMulipartResolver
for Apache Commons FileUpload and StandardServletMultipartResolver
for the Servlet 3.0 API.
Since most modern web applications use a Servlet 3.0 container, let's see how the FileUpload functionality can be handled using StandardServletMultipartResolver
with the help of following example:
Register your
MultipartResolver
in yourservlet-context.xml
file (or add it programmatically if you are using a Java configuration):<beans:bean id="multipartResolver" class="org.springframework.web.multipart.support.StandardServletMultipartResolver"> </beans:bean>
Add multipart configuration support to your
DispatcherServlet
in yourweb.xml
(or JavaConfig) file:<servlet> <servlet-name>appServlet</servlet-name> ... <multipart...