接口 PortletMultipartResolver
- 所有已知实现类:
CommonsPortletMultipartResolver
public interface PortletMultipartResolver
Portlet version of Spring's multipart resolution strategy for file uploads as defined in RFC 1867.Implementations are typically usable both within any application context and standalone.
There is one concrete implementation included in Spring:
CommonsMultipartResolver
for Apache Commons FileUpload
There is no default resolver implementation used for Spring
DispatcherPortlets
, as an application might choose to parse its multipart requests itself. To define an implementation, create a bean with the id "portletMultipartResolver" in aDispatcherPortlet's
application context. Such a resolver gets applied to all requests handled by thatDispatcherPortlet
.If a
DispatcherPortlet
detects a multipart request, it will resolve it via the configuredPortletMultipartResolver
and pass on a wrapped PortletActionRequest
. Controllers can then cast their given request to theMultipartActionRequest
interface, being able to accessMultipartFiles
. Note that this cast is only supported in case of an actual multipart request.public void handleActionRequest(ActionRequest request, ActionResponse response) { MultipartActionRequest multipartRequest = (MultipartActionRequest) request; MultipartFile multipartFile = multipartRequest.getFile("image"); ... }
Instead of direct access, command or form controllers can register aByteArrayMultipartFileEditor
orStringMultipartFileEditor
with their data binder, to automatically apply multipart content to form bean properties.Note: There is hardly ever a need to access the
MultipartResolver
itself from application code. It will simply do its work behind the scenes, makingMultipartActionRequests
available to controllers.- 从以下版本开始:
- 2.0
- 作者:
- Juergen Hoeller
- 另请参阅:
MultipartActionRequest
,MultipartFile
,CommonsPortletMultipartResolver
,ByteArrayMultipartFileEditor
,StringMultipartFileEditor
,DispatcherPortlet
方法概要
所有方法 实例方法 抽象方法 修饰符和类型 方法 说明 void
cleanupMultipart(MultipartActionRequest request)
Cleanup any resources used for the multipart handling, such as storage for any uploaded file(s).boolean
isMultipart(ActionRequest request)
Determine if the given request contains multipart content.MultipartActionRequest
resolveMultipart(ActionRequest request)
Parse the given portlet request into multipart files and parameters, and wrap the request inside a MultipartActionRequest object that provides access to file descriptors and makes contained parameters accessible via the standard PortletRequest methods.
方法详细资料
isMultipart
boolean isMultipart(ActionRequest request)
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.- 参数:
request
- the portlet request to be evaluated- 返回:
- whether the request contains multipart content
resolveMultipart
MultipartActionRequest resolveMultipart(ActionRequest request) throws MultipartException
Parse the given portlet request into multipart files and parameters, and wrap the request inside a MultipartActionRequest object that provides access to file descriptors and makes contained parameters accessible via the standard PortletRequest methods.- 参数:
request
- the portlet request to wrap (must be of a multipart content type)- 返回:
- the wrapped portlet request
- 抛出:
MultipartException
- if the portlet request is not multipart, or if implementation-specific problems are encountered (such as exceeding file size limits)- 另请参阅:
MultipartRequest.getFile(java.lang.String)
,MultipartRequest.getFileNames()
,MultipartRequest.getFileMap()
,PortletRequest.getParameter(java.lang.String)
,PortletRequest.getParameterNames()
,PortletRequest.getParameterMap()
cleanupMultipart
void cleanupMultipart(MultipartActionRequest request)
Cleanup any resources used for the multipart handling, such as storage for any uploaded file(s).- 参数:
request
- the request to cleanup resources for