Class MultipartFilter
- All Implemented Interfaces:
Filter
,Aware
,BeanNameAware
,DisposableBean
,InitializingBean
,EnvironmentAware
,EnvironmentCapable
,ServletContextAware
MultipartResolver
.
in the root web application context.
Looks up the MultipartResolver in Spring's root web application context.
Supports a "multipartResolverBeanName" filter init-param in web.xml
;
the default bean name is "filterMultipartResolver".
If no MultipartResolver bean is found, this filter falls back to a default
MultipartResolver: StandardServletMultipartResolver
for Servlet
oontainers, based on a multipart-config section in web.xml
.
Note however that at present the Servlet specification only defines how to
enable multipart configuration on a Servlet and as a result multipart request
processing is likely not possible in a Filter unless the Servlet container
provides a workaround such as Tomcat's "allowCasualMultipartParsing" property.
MultipartResolver lookup is customizable: Override this filter's
lookupMultipartResolver
method to use a custom MultipartResolver
instance, for example if not using a Spring web application context.
Note that the lookup method should not create a new MultipartResolver instance
for each call but rather return a reference to a pre-built instance.
Note: This filter is an alternative to using DispatcherServlet's
MultipartResolver support, for example for web applications with custom web views
which do not use Spring's web MVC, or for custom filters applied before a Spring MVC
DispatcherServlet (e.g. HiddenHttpMethodFilter
).
In any case, this filter should not be combined with servlet-specific multipart resolution.
- Since:
- 08.10.2003
- Author:
- Juergen Hoeller
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
The default name for the multipart resolver bean.Fields inherited from class org.springframework.web.filter.OncePerRequestFilter
ALREADY_FILTERED_SUFFIX
Fields inherited from class org.springframework.web.filter.GenericFilterBean
logger
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
doFilterInternal
(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) Check for a multipart request via this filter's MultipartResolver, and wrap the original request with a MultipartHttpServletRequest if appropriate.protected String
Return the bean name of the MultipartResolver to fetch from Spring's root application context.protected MultipartResolver
Look for a MultipartResolver bean in the root web application context.protected MultipartResolver
Look up the MultipartResolver that this filter should use, taking the current HTTP request as argument.void
setMultipartResolverBeanName
(String multipartResolverBeanName) Set the bean name of the MultipartResolver to fetch from Spring's root application context.Methods inherited from class org.springframework.web.filter.OncePerRequestFilter
doFilter, doFilterNestedErrorDispatch, getAlreadyFilteredAttributeName, isAsyncDispatch, isAsyncStarted, shouldNotFilter, shouldNotFilterAsyncDispatch, shouldNotFilterErrorDispatch
Methods inherited from class org.springframework.web.filter.GenericFilterBean
addRequiredProperty, afterPropertiesSet, createEnvironment, destroy, getEnvironment, getFilterConfig, getFilterName, getServletContext, init, initBeanWrapper, initFilterBean, setBeanName, setEnvironment, setServletContext
-
Field Details
-
DEFAULT_MULTIPART_RESOLVER_BEAN_NAME
The default name for the multipart resolver bean.- See Also:
-
-
Constructor Details
-
MultipartFilter
public MultipartFilter()
-
-
Method Details
-
setMultipartResolverBeanName
Set the bean name of the MultipartResolver to fetch from Spring's root application context. Default is "filterMultipartResolver". -
getMultipartResolverBeanName
Return the bean name of the MultipartResolver to fetch from Spring's root application context. -
doFilterInternal
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException Check for a multipart request via this filter's MultipartResolver, and wrap the original request with a MultipartHttpServletRequest if appropriate.All later elements in the filter chain, most importantly servlets, benefit from proper parameter extraction in the multipart case, and are able to cast to MultipartHttpServletRequest if they need to.
- Specified by:
doFilterInternal
in classOncePerRequestFilter
- Throws:
ServletException
IOException
-
lookupMultipartResolver
Look up the MultipartResolver that this filter should use, taking the current HTTP request as argument.The default implementation delegates to the
lookupMultipartResolver
without arguments.- Returns:
- the MultipartResolver to use
- See Also:
-
lookupMultipartResolver
Look for a MultipartResolver bean in the root web application context. Supports a "multipartResolverBeanName" filter init param; the default bean name is "filterMultipartResolver".This can be overridden to use a custom MultipartResolver instance, for example if not using a Spring web application context.
- Returns:
- the MultipartResolver instance
-