jombo123
2010-03-19 10:39 阅读 263
已采纳

为什么上传大文件就是空值,而上传小文件没有问题

项目有有时候会有大文件上传,四五百M,有时候上传接收不到流
可是上传小文件就没有问题
就是用得Formfile
好奇怪
项目架子struts1+spring2.5+hibernate

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

6条回答 默认 最新

  • 已采纳
    javatyper javatyper 2010-03-19 12:18

    上传文件时,会处理request中的内容。
    最终才会调用commonupload组件上传
    struts中类
    org.apache.struts.upload.CommonsMultipartRequestHandler
    做了这一操作
    [code="java"] public void handleRequest(HttpServletRequest request)
    throws ServletException {
    // Get the app config for the current request.
    ModuleConfig ac =
    (ModuleConfig) request.getAttribute(Globals.MODULE_KEY);

        // Create and configure a DIskFileUpload instance.
        DiskFileUpload upload = new DiskFileUpload();
    
        // The following line is to support an "EncodingFilter"
        // see http://issues.apache.org/bugzilla/show_bug.cgi?id=23255
        upload.setHeaderEncoding(request.getCharacterEncoding());
    
        // Set the maximum size before a FileUploadException will be thrown.
        upload.setSizeMax(getSizeMax(ac));
    
        // Set the maximum size that will be stored in memory.
        upload.setSizeThreshold((int) getSizeThreshold(ac));
    
        // Set the the location for saving data on disk.
        upload.setRepositoryPath(getRepositoryPath(ac));
    
        // Create the hash tables to be populated.
        elementsText = new Hashtable();
        elementsFile = new Hashtable();
        elementsAll = new Hashtable();
    
        // Parse the request into file items.
        List items = null;
    
        try {
            items = upload.parseRequest(request);
        } catch (DiskFileUpload.SizeLimitExceededException e) {
            // Special handling for uploads that are too big.
            request.setAttribute(MultipartRequestHandler.ATTRIBUTE_MAX_LENGTH_EXCEEDED,
                Boolean.TRUE);
    
            return;
        } catch (FileUploadException e) {
            log.error("Failed to parse multipart request", e);
            throw new ServletException(e);
        }
    
        // Partition the items into form fields and files.
        Iterator iter = items.iterator();
    
        while (iter.hasNext()) {
            FileItem item = (FileItem) iter.next();
    
            if (item.isFormField()) {
                addTextParameter(request, item);
            } else {
                addFileParameter(item);
            }
        }
    }[/code]
    

    而在代码
    [code="java"]upload.setSizeMax(getSizeMax(ac))[/code]
    中会设置上传的最大值限制,如果超过最大值,会在request当值一个标识过大的参数值为true
    [code="java"]request.setAttribute(MultipartRequestHandler.ATTRIBUTE_MAX_LENGTH_EXCEEDED,
    Boolean.TRUE);[/code]

    然后调用者会根据request的MultipartRequestHandler.ATTRIBUTE_MAX_LENGTH_EXCEEDED是不是true来决定来不要放null值

    当然这个最大值也是可以配置文件中配置的。注意最后在配置的数字后带上M,K子符号
    [code="java"] [/code]

    点赞 评论 复制链接分享
  • xiaolongfeixiang 拽拽的初行者 2010-03-19 10:41

    Struts的默认的最大上传文件有限制。

    点赞 评论 复制链接分享
  • qwe_rt qwe_rt 2010-03-19 10:42

    enctype="multipart/form-data"去掉

    点赞 评论 复制链接分享
  • xiaolongfeixiang 拽拽的初行者 2010-03-19 10:44

    可以在 struts.xml中配置大小(以kb计)

    [code="xml"]
    [/code]

    但是,大文件还是建议用FTP。

    点赞 评论 复制链接分享
  • iteye_13500 iteye_13500 2010-03-19 10:45
    点赞 评论 复制链接分享
  • wanghaolovezlq wanghaolovezlq 2010-03-19 10:52
    点赞 评论 复制链接分享

相关推荐