上传文件出错:org.apache.commons.fileupload.FileUploadBase$IOFileUploadException: Processing of multipart/form-data request failed. Stream ended unexpectedly

最近做一个web项目中有上传文件的功能,已经写出并在本地和部署到服务器上测试了好几个文件上传都没问题(我用的是tomcat)。后来又上传了一个700多K的文件(前边的都是不足600K的,并且这个word文件用到了vb,比较复杂,可能造成读取较慢),在本地也是可以的,部署到服务器后在服务器上用服务器的本地浏览器上传也是可以的,但是部署到服务器上在其他地方通过浏览器访问上传却不行,情况是运行很久,然后出现“不能显示此页面”的字样。我就很奇怪,为什么同样的程序在本地和服务器上的效果却是不一样的?我看了服务器上tomcat下产生的日志,报的错误为

2013-11-20 09:17:39,865 WARN (org.apache.struts2.dispatcher.multipart.MultiPartRequest:60) - Unable to parse request
org.apache.commons.fileupload.FileUploadBase$IOFileUploadException: Processing of multipart/form-data request failed. Stream ended unexpectedly
at org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:367)
at org.apache.struts2.dispatcher.multipart.JakartaMultiPartRequest.parseRequest(JakartaMultiPartRequest.java:145)
at org.apache.struts2.dispatcher.multipart.JakartaMultiPartRequest.processUpload(JakartaMultiPartRequest.java:88)
at org.apache.struts2.dispatcher.multipart.JakartaMultiPartRequest.parse(JakartaMultiPartRequest.java:80)
at org.apache.struts2.dispatcher.multipart.MultiPartRequestWrapper.<init>(MultiPartRequestWrapper.java:75)
at org.apache.struts2.dispatcher.Dispatcher.wrapRequest(Dispatcher.java:722)
at org.apache.struts2.dispatcher.ng.PrepareOperations.wrapRequest(PrepareOperations.java:131)
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:83)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.quliuwuyi.util.LoginFilter.doFilter(LoginFilter.java:60)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:615)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:662)
Caused by: org.apache.commons.fileupload.MultipartStream$MalformedStreamException: Stream ended unexpectedly
at org.apache.commons.fileupload.MultipartStream$ItemInputStream.makeAvailable(MultipartStream.java:983)
at org.apache.commons.fileupload.MultipartStream$ItemInputStream.read(MultipartStream.java:887)
at java.io.InputStream.read(InputStream.java:82)
at org.apache.commons.fileupload.util.Streams.copy(Streams.java:94)
at org.apache.commons.fileupload.util.Streams.copy(Streams.java:64)
at org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:362)
... 23 more

然后在百度和谷歌上各种搜索,大多数认为是超时而断开连接。对于解决办法一般给的不够全面,现综合给出如下:

(1)首先,上传页面上面的 form 标签要设enctype="multipart/form-data" 参数

(2)修改tomcat配置文件server.xml,找到类似于下面配置:

<Connector port="8086" maxHttpHeaderSize="8192"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
connectionTimeout="20000" disableUploadTimeout="true" />
将上面的参数disableUploadTimeout值改为false即可。

(3)上边(1)是我的程序中已经设置的,修改了(2)所述的配置后依然不能运行,后来又修改了tomcat配置文件server.xml中的另外一处:

<Connector executor="tomcatThreadPool"
port="8080" protocol="HTTP/1.1" 
connectionTimeout="20000" 
redirectPort="8443" /> 也在里边加入了disableUploadTimeout="false"一句。

   用了以上方法仍然不能解决,后来想到可能是服务器外加了防火墙或者限制了上传文件的大小之类的,联系网络中心进行相关设置进行设置即可。

时间: 2024-12-10 21:39:24

上传文件出错:org.apache.commons.fileupload.FileUploadBase$IOFileUploadException: Processing of multipart/form-data request failed. Stream ended unexpectedly的相关文章

Unable to parse request org.apache.commons.fileupload.FileUploadBase$IOFileUploadException: Processing of multipart/form-data request failed. null

最近做一个web项目中有上传文件的功能,已经写出并在本地和部署到服务器上测试了好几个文件上传都没问题(我用的是tomcat).部署上服务器,上传图片时有的图片大就回在tomcat日志报如下错误: Unable to parse requestorg.apache.commons.fileupload.FileUploadBase$IOFileUploadException: Processing of multipart/form-data request failed. null at org

hadoopmaster主机上传文件出错: put: File /a.txt._COPYING_ could only be replicated to 0 nodes instead of minReplication (=1). There are 3 datanode(s) running and 3 node(s) are excluded in this operation.

刚开始装好hadoop的时候,namenode机上传文件没有错误,今天打开时突然不能上传文件,报错 put: File /a.txt._COPYING_ could only be replicated to 0 nodes instead of minReplication (=1). There are 3 datanode(s) running and 3 node(s) are excluded in this operation. 上网查了一下,先把,nnamenode和datanod

为什么上传文件的表单里面要加一个属性ENCTYPE=MULTIPART/FORM-DATA?

首先知道enctype这个属性管理的是表单的MIME编码.共有三个值可选:1.application/x-www-form-urlencoded2.multipart/form-data3.text/plain其中application/x-www-form-urlencoded是默认值,作用是设置表单传输的编码.例如我们在AJAX中见过xmlHttp.setRequestHeader("Content-Type","application/x-www-form- urlen

java模拟http请求上传文件,基于Apache的httpclient

1.依赖 模拟http端的请求需要依赖Apache的httpclient,需要第三方JSON支持,项目中添加 <dependency> <groupId>org.apache</groupId> <artifactId>httpclient</artifactId> <version>4.1.2</version> </dependency> <dependency> <groupId>

Spring 中Apache Commons上传文件

在用Apache Commons完成文件上传功能需有的几步: 1.导入两个架包:commons-fileupload.jar和commons-io.jar maven中: 1 <dependency> 2 <groupId>commons-fileupload</groupId> 3 <artifactId>commons-fileupload</artifactId> 4 <version>1.3</version> 5

SpringMVC上传文件进度显示

效果图: FileUploadController.java import java.io.File; import java.util.List; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import org.apache.commons.fileupload.FileIt

第十一章节-上传文件

在Spring MVC中处理文件上传有两种方法: (1)使用Common FileUp元件. (2)使用Servlet 3.0和更高版本对文件上传的支持. 一.客户端编程 为了上传文件,要将html表格的enctype设置为multipart/form-data,表格中还要有一个类型为file的input元素,它会显示成一个按钮,点击时会打开一个选择文件的对话框. 如下: <form action="action" enctype="multipart/form-dat

【springmvc】springmvc中如何上传文件

使用到的组件:可自行根据情况选择版本 <!--上传依赖包--> <dependency> <groupId>commons-fileupload</groupId> <artifactId>commons-fileupload</artifactId> <version>1.3.2</version> </dependency> <!--commons-upload依赖包begin-->

springmvc上传文件,抄别人的

SpringMVC中的文件上传 分类: SpringMVC 2012-05-17 12:55 26426人阅读 评论(13) 收藏 举报 stringuserinputclassencoding 这是用的是SpringMVC-3.1.1.commons-fileupload-1.2.2和io-2.0.1 首先是web.xml [html] view plaincopyprint? <?xml version="1.0" encoding="UTF-8"?>