etf.org/rfc/rfc1867.txt">RFC 1867. Implementations are typically usable both within an application context and standalone.
There are two concrete implementations included in Spring, as of Spring 3.1:
- {@link org.springframework.web.multipart.commons.CommonsMultipartResolver} for Jakarta Commons FileUpload
- {@link org.springframework.web.multipart.support.StandardServletMultipartResolver} for Servlet 3.0 Part API
There is no default resolver implementation used for Spring {@link org.springframework.web.servlet.DispatcherServlet DispatcherServlets}, as an application might choose to parse its multipart requests itself. To define an implementation, create a bean with the id "multipartResolver" in a {@link org.springframework.web.servlet.DispatcherServlet DispatcherServlet's}application context. Such a resolver gets applied to all requests handled by that {@link org.springframework.web.servlet.DispatcherServlet}.
If a {@link org.springframework.web.servlet.DispatcherServlet} detectsa multipart request, it will resolve it via the configured {@link org.springframework.web.multipart.MultipartResolver} and pass on awrapped {@link javax.servlet.http.HttpServletRequest}. Controllers can then cast their given request to the {@link org.springframework.web.multipart.MultipartHttpServletRequest}interface, which permits access to any {@link org.springframework.web.multipart.MultipartFile MultipartFiles}. Note that this cast is only supported in case of an actual multipart request.
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) { MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; MultipartFile multipartFile = multipartRequest.getFile("image"); ... }
Instead of direct access, command or form controllers can register a {@link org.springframework.web.multipart.support.ByteArrayMultipartFileEditor}or {@link org.springframework.web.multipart.support.StringMultipartFileEditor}with their data binder, to automatically apply multipart content to command bean properties.
As an alternative to using a {@link org.springframework.web.multipart.MultipartResolver} with a{@link org.springframework.web.servlet.DispatcherServlet}, a {@link org.springframework.web.multipart.support.MultipartFilter} can beregistered in web.xml
. It will delegate to a corresponding {@link org.springframework.web.multipart.MultipartResolver} bean in the rootapplication context. This is mainly intended for applications that do not use Spring's own web MVC framework.
Note: There is hardly ever a need to access the {@link org.springframework.web.multipart.MultipartResolver} itselffrom application code. It will simply do its work behind the scenes, making {@link org.springframework.web.multipart.MultipartHttpServletRequest MultipartHttpServletRequests}available to controllers.
@author Juergen Hoeller
@author Trevor D. Cook
@since 29.09.2003
@see MultipartHttpServletRequest
@see MultipartFile
@see org.springframework.web.multipart.commons.CommonsMultipartResolver
@see org.springframework.web.multipart.support.ByteArrayMultipartFileEditor
@see org.springframework.web.multipart.support.StringMultipartFileEditor
@see org.springframework.web.servlet.DispatcherServlet