类 MultipartFilter
- java.lang.Object
- org.springframework.web.filter.GenericFilterBean
- org.springframework.web.filter.OncePerRequestFilter
- org.springframework.web.multipart.support.MultipartFilter
- 所有已实现的接口:
Filter
,Aware
,BeanNameAware
,DisposableBean
,InitializingBean
,EnvironmentAware
,EnvironmentCapable
,ServletContextAware
public class MultipartFilter extends OncePerRequestFilter
Servlet Filter that resolves multipart requests via aMultipartResolver
. 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 3.0, based on a multipart-config section inweb.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.- 从以下版本开始:
- 08.10.2003
- 作者:
- Juergen Hoeller
- 另请参阅:
setMultipartResolverBeanName(java.lang.String)
,lookupMultipartResolver(javax.servlet.http.HttpServletRequest)
,MultipartResolver
,DispatcherServlet
字段概要
字段 修饰符和类型 字段 说明 static String
DEFAULT_MULTIPART_RESOLVER_BEAN_NAME
从类继承的字段 org.springframework.web.filter.OncePerRequestFilter
ALREADY_FILTERED_SUFFIX
从类继承的字段 org.springframework.web.filter.GenericFilterBean
logger
构造器概要
构造器 构造器 说明 MultipartFilter()
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 protected 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
getMultipartResolverBeanName()
Return the bean name of the MultipartResolver to fetch from Spring's root application context.protected MultipartResolver
lookupMultipartResolver()
Look for a MultipartResolver bean in the root web application context.protected MultipartResolver
lookupMultipartResolver(HttpServletRequest request)
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.从类继承的方法 org.springframework.web.filter.OncePerRequestFilter
doFilter, getAlreadyFilteredAttributeName, isAsyncDispatch, isAsyncStarted, shouldNotFilter, shouldNotFilterAsyncDispatch, shouldNotFilterErrorDispatch
从类继承的方法 org.springframework.web.filter.GenericFilterBean
addRequiredProperty, afterPropertiesSet, createEnvironment, destroy, getEnvironment, getFilterConfig, getFilterName, getServletContext, init, initBeanWrapper, initFilterBean, setBeanName, setEnvironment, setServletContext
字段详细资料
DEFAULT_MULTIPART_RESOLVER_BEAN_NAME
public static final String DEFAULT_MULTIPART_RESOLVER_BEAN_NAME
- 另请参阅:
- 常量字段值
构造器详细资料
MultipartFilter
public MultipartFilter()
方法详细资料
setMultipartResolverBeanName
public void setMultipartResolverBeanName(String multipartResolverBeanName)
Set the bean name of the MultipartResolver to fetch from Spring's root application context. Default is "filterMultipartResolver".
getMultipartResolverBeanName
protected String 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.
lookupMultipartResolver
protected MultipartResolver lookupMultipartResolver(HttpServletRequest request)
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.- 返回:
- the MultipartResolver to use
- 另请参阅:
lookupMultipartResolver()
lookupMultipartResolver
protected MultipartResolver 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.
- 返回:
- the MultipartResolver instance, or
null
if none found