Apache Commons Fileupload/Tomcat 无法处理 out.flush() [英] Apache Commons Fileupload / Tomcat cant cope with out.flush()

查看:49
本文介绍了Apache Commons Fileupload/Tomcat 无法处理 out.flush()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道一种解决方法,如果您尝试刷新 servlet 输出流,apache commons fileupload 会抛出以下异常?

Does anyone know of a workaround whereby if you are trying to flush the servlet output stream, apache commons fileupload throws the following exception?

FileUploadException: Processing of multipart/form-data request failed. Stream ended unexpectedly

基本上我有代码循环遍历使用 apache commons fileupload 上传的每个文件,然后我尝试 out.flush() 一些关于每个文件的统计信息.即:

Basically I have code that loops through each file uploaded using apache commons fileupload, and then am trying to out.flush() some stats about each file. ie:

    FileItemFactory factory = new DiskFileItemFactory();
    ServletFileUpload upload = new ServletFileUpload(factory);
    List<FileItem> items = upload.parseRequest(request);

    for(FileItem field : items) {
        if (!field.isFormField() && field.getName().length()>0 && field.getName().getSize()>0) {
            ArticleImport helper = new ArticleImport(new ArticleImportResponder(user,out));
            // This helper object uses out.flush() to provide feedback to the user.
            helper.process(field.getInputStream(), user);
            }
        }
    }

Apache Tomcat 6.0.20 不会出现该问题,但在早期版本中会出现.

The problem does not occur in Apache Tomcat 6.0.20, but it does occur in earlier versions.

推荐答案

不幸的是,这是一个已知错误,除了确保您使用至少 6.0.20 外,您无能为力.

Unfortunately this is a known bug, there is nothing you can do about it except ensure that your using at least 6.0.20.

您可以检测到哪个版本的 tomcat 正在运行,并使用它来确定您是否可以使用以下调用使用 out.flush():

You could detect which version of tomcat is running and use that to determine if you can use out.flush() using the following call:

javax.servlet.ServletContext.getServerInfo();

这篇关于Apache Commons Fileupload/Tomcat 无法处理 out.flush()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆