码迷,mamicode.com
首页 > 编程语言 > 详细

spring multipart源码分析:

时间:2017-07-03 14:12:07      阅读:250      评论:0      收藏:0      [点我收藏+]

标签:throw   提取   style   contain   use   handler   containe   bool   whether   

1、MultipartResolver

     MultipartResolver接口提供了spring mvc的上传视图,MultipartResolver实例在请求转交给handlermapping之前。 也就是说DispatcherServlet ,在请求映射的时候,若找到MultipartResolver这个实例的话,

     就直接把请求转交给MultipartResolver

     

技术分享
/**
     * Determine if the given request contains multipart content.
     * <p>Will typically check for content type "multipart/form-data", but the actually
     * accepted requests might depend on the capabilities of the resolver implementation.
     * @param request the servlet request to be evaluated
     * @return whether the request contains multipart content
     */
    boolean isMultipart(HttpServletRequest request);

    /**
     * Parse the given HTTP request into multipart files and parameters,
     * and wrap the request inside a
     * {@link org.springframework.web.multipart.MultipartHttpServletRequest}
     * object that provides access to file descriptors and makes contained
     * parameters accessible via the standard ServletRequest methods.
     * @param request the servlet request to wrap (must be of a multipart content type)
     * @return 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 MultipartHttpServletRequest#getFile
     * @see MultipartHttpServletRequest#getFileNames
     * @see MultipartHttpServletRequest#getFileMap
     * @see javax.servlet.http.HttpServletRequest#getParameter
     * @see javax.servlet.http.HttpServletRequest#getParameterNames
     * @see javax.servlet.http.HttpServletRequest#getParameterMap
     */
    MultipartHttpServletRequest resolveMultipart(HttpServletRequest request) throws MultipartException;

    /**
     * Cleanup any resources used for the multipart handling,
     * like a storage for the uploaded files.
     * @param request the request to cleanup resources for
     */
    void cleanupMultipart(MultipartHttpServletRequest request);
View Code

  MultipartResolver接口提供了3个方法:

      boolean isMultipart(HttpServletRequest request): 检查当前请求是否是multipart content type

   resolveMultipart: 将httprequest转换成MultipartHttpServletRequest 

      

      已知的子类: CommonsMultipartResolverStandardServletMultipartResolver

  1. 第一个需要使用 Apache 的 commons-fileupload 等 jar 包支持,但它能在比较旧的 servlet 版本中使用。
  2. 第二个不需要第三方 jar 包支持,它使用 servlet 内置的上传功能,但是只能在 Servlet 3 以上的版本使用。

 

2、multipartRequest

 

  multipartRequest接口可以讲request对象封装成multipartRequest,提取请求的信息,MultipartReques类主要是对文件上传进行的处理。

spring multipart源码分析:

标签:throw   提取   style   contain   use   handler   containe   bool   whether   

原文地址:http://www.cnblogs.com/kimobolo/p/7110575.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!