站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > Spring Framework 2.1.0 API 文档英文版

CommonsMultipartResolver (Spring Framework API 2.1) - Spring Framework 2.1.0 API 文档英文版


The Spring Framework

org.springframework.web.multipart.commons
Class CommonsMultipartResolver

java.lang.Object
  extended by org.springframework.web.multipart.commons.CommonsFileUploadSupport
      extended by org.springframework.web.multipart.commons.CommonsMultipartResolver
All Implemented Interfaces:
ServletContextAware, MultipartResolver

public class CommonsMultipartResolver
extends CommonsFileUploadSupport
implements MultipartResolver, ServletContextAware

Servlet-based MultipartResolver implementation for Jakarta Commons FileUpload 1.1 or higher.

Provides maxUploadSize, maxInMemorySize, and defaultEncoding settings as bean properties (inherited from CommonsFileUploadSupport). See respective ServletFileUpload / DiskFileItemFactory properties (sizeMax, sizeThreshold, headerEncoding) for details in terms of defaults and accepted values.

Saves temporary files to the servlet container's temporary directory. Needs to be initialized either by an application context or via the constructor that takes a ServletContext (for standalone usage).

NOTE: As of Spring 2.0, this multipart resolver requires Commons FileUpload 1.1 or higher. The implementation does not use any deprecated FileUpload 1.0 API anymore, to be compatible with future Commons FileUpload releases.

Since:
29.09.2003
Author:
Trevor D. Cook, Juergen Hoeller
See Also:
CommonsMultipartResolver(ServletContext), CommonsMultipartFile, PortletMultipartResolver, ServletFileUpload, DiskFileItemFactory

Nested Class Summary
 
Nested classes/interfaces inherited from class org.springframework.web.multipart.commons.CommonsFileUploadSupport
CommonsFileUploadSupport.MultipartParsingResult
 
Field Summary
 
Fields inherited from class org.springframework.web.multipart.commons.CommonsFileUploadSupport
logger
 
Constructor Summary
CommonsMultipartResolver()
          Constructor for use as bean.
CommonsMultipartResolver(ServletContext servletContext)
          Constructor for standalone usage.
 
Method Summary
 void cleanupMultipart(MultipartHttpServletRequest request)
          Cleanup any resources used for the multipart handling, like a storage for the uploaded files.
protected  String determineEncoding(HttpServletRequest request)
          Determine the encoding for the given request.
 boolean isMultipart(HttpServletRequest request)
          Determine if the given request contains multipart content.
protected  FileUpload newFileUpload(FileItemFactory fileItemFactory)
          Initialize the underlying org.apache.commons.fileupload.servlet.ServletFileUpload instance.
 MultipartHttpServletRequest resolveMultipart(HttpServletRequest request)
          Parse the given HTTP request into multipart files and parameters, and wrap the request inside a MultipartHttpServletRequest object that provides access to file descriptors and makes contained parameters accessible via the standard ServletRequest methods.
 void setServletContext(ServletContext servletContext)
          Set the ServletContext that this object runs in.
 
Methods inherited from class org.springframework.web.multipart.commons.CommonsFileUploadSupport
cleanupFileItems, getDefaultEncoding, getFileItemFactory, getFileUpload, isUploadTempDirSpecified, newFileItemFactory, parseFileItems, prepareFileUpload, setDefaultEncoding, setMaxInMemorySize, setMaxUploadSize, setUploadTempDir
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CommonsMultipartResolver

public CommonsMultipartResolver()
Constructor for use as bean. Determines the servlet container's temporary directory via the ServletContext passed in as through the ServletContextAware interface (typically by a WebApplicationContext).

See Also:
setServletContext(javax.servlet.ServletContext), ServletContextAware, WebApplicationContext

CommonsMultipartResolver

public CommonsMultipartResolver(ServletContext servletContext)
Constructor for standalone usage. Determines the servlet container's temporary directory via the given ServletContext.

Parameters:
servletContext - the ServletContext to use
Method Detail

newFileUpload

protected FileUpload newFileUpload(FileItemFactory fileItemFactory)
Initialize the underlying org.apache.commons.fileupload.servlet.ServletFileUpload instance. Can be overridden to use a custom subclass, e.g. for testing purposes.

Specified by:
newFileUpload in class CommonsFileUploadSupport
Parameters:
fileItemFactory - the Commons FileItemFactory to use
Returns:
the new ServletFileUpload instance

setServletContext

public void setServletContext(ServletContext servletContext)
Description copied from interface: ServletContextAware
Set the ServletContext that this object runs in.

Invoked after population of normal bean properties but before an init callback like InitializingBean's afterPropertiesSet or a custom init-method. Invoked after ApplicationContextAware's setApplicationContext.

Specified by:
setServletContext in interface ServletContextAware
Parameters:
servletContext - ServletContext object to be used by this object
See Also:
InitializingBean.afterPropertiesSet(), ApplicationContextAware.setApplicationContext(org.springframework.context.ApplicationContext)

isMultipart

public boolean isMultipart(HttpServletRequest request)
Description copied from interface: MultipartResolver
Determine if the given request contains multipart content.

Will typically check for content type "multipart/form-data", but the actually accepted requests might depend on the capabilities of the resolver implementation.

Specified by:
isMultipart in interface MultipartResolver
Parameters:
request - the servlet request to be evaluated
Returns:
whether the request contains multipart content

resolveMultipart

public MultipartHttpServletRequest resolveMultipart(HttpServletRequest request)
                                             throws MultipartException
Description copied from interface: MultipartResolver
Parse the given HTTP request into multipart files and parameters, and wrap the request inside a MultipartHttpServletRequest object that provides access to file descriptors and makes contained parameters accessible via the standard ServletRequest methods.

Specified by:
resolveMultipart in interface MultipartResolver
Parameters:
request - the servlet request to wrap (must be of a multipart content type)
Returns:
the wrapped servlet request
Throws:
MultipartException - if the servlet request is not multipart, or if implementation-specific problems are encountered (such as exceeding file size limits)
See Also:
MultipartHttpServletRequest.getFile(java.lang.String), MultipartHttpServletRequest.getFileNames(), MultipartHttpServletRequest.getFileMap(), ServletRequest.getParameter(java.lang.String), ServletRequest.getParameterNames(), ServletRequest.getParameterMap()

determineEncoding

protected String determineEncoding(HttpServletRequest request)
Determine the encoding for the given request. Can be overridden in subclasses.

The default implementation checks the request encoding, falling back to the default encoding specified for this resolver.

Parameters:
request - current HTTP request
Returns:
the encoding for the request (never null)
See Also:
ServletRequest.getCharacterEncoding(), CommonsFileUploadSupport.setDefaultEncoding(java.lang.String)

cleanupMultipart

public void cleanupMultipart(MultipartHttpServletRequest request)
Description copied from interface: MultipartResolver
Cleanup any resources used for the multipart handling, like a storage for the uploaded files.

Specified by:
cleanupMultipart in interface MultipartResolver
Parameters:
request - the request to cleanup resources for

The Spring Framework

Copyright © 2002-2007 The Spring Framework.