A strategy interface for multipart file upload resolution in accordance
with RFC 1867.
Implementations are typically usable both within an application context
and standalone.
There is only one concrete implementation included in Spring,
as of Spring 2.5:
There is no default resolver implementation used for Spring
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
org.springframework.web.servlet.DispatcherServlet DispatcherServlet's application context. Such a resolver gets applied to all requests handled
by that
org.springframework.web.servlet.DispatcherServlet .
If a
org.springframework.web.servlet.DispatcherServlet detects
a multipart request, it will resolve it via the configured
org.springframework.web.multipart.MultipartResolver and pass on a
wrapped
javax.servlet.http.HttpServletRequest .
Controllers can then cast their given request to the
org.springframework.web.multipart.MultipartHttpServletRequest interface, which permits access to any
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
org.springframework.web.multipart.support.ByteArrayMultipartFileEditor or
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
org.springframework.web.multipart.MultipartResolver with a
org.springframework.web.servlet.DispatcherServlet ,
a
org.springframework.web.multipart.support.MultipartFilter can be
registered in web.xml . It will delegate to a corresponding
org.springframework.web.multipart.MultipartResolver bean in the root
application 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
org.springframework.web.multipart.MultipartResolver itself
from application code. It will simply do its work behind the scenes,
making
org.springframework.web.multipart.MultipartHttpServletRequest MultipartHttpServletRequests available to controllers.
author: Juergen Hoeller author: Trevor D. Cook since: 29.09.2003 See Also: MultipartHttpServletRequest See Also: MultipartFile See Also: org.springframework.web.multipart.commons.CommonsMultipartResolver See Also: org.springframework.web.multipart.support.ByteArrayMultipartFileEditor See Also: org.springframework.web.multipart.support.StringMultipartFileEditor See Also: org.springframework.web.servlet.DispatcherServlet |