java.io.IOException: Corrupt form data: premature ending

Cos1.3.1+Struts1.2->放在纯jsp里是可以的,但是放在Struts1.2的action中就有问题了,要求解决方案.如果换一中lib,必须处理多个file request,请明示.

                                                         < form  name ="form_attach_add"  method ="post"
                                                            enctype
="multipart/form-data"
                                                            action
="<%=path%>/addNodeAttach.do" >
                                                            
< input  name ="nodeOid"  type ="hidden"  value ="<%=nodeOid%>" >
                                                            
< input  name ="nodeTitle"  type ="hidden"
                                                                value
="<%=nodeTitle%>" >
                                                            
< input  name ="stat"  type ="hidden"  value ="0" >
                                                            
< input  name ="title"  type ="hidden"  value ="" >
                                                            
< input  name ="type"  type ="hidden"  value ="0" >
                                                            
< table  width ="100%"  border ="1"  cellpadding ="5"
                                                                cellspacing
="0"  bordercolor ="#999999"
                                                                style
="border-collapse: collapse"  align ="center" >
                                                                
< tr  bgcolor ="FFFFF4" >
                                                                    
< td  width ="30%"  height ="22" >
                                                                        附件:
                                                                    
</ td >
                                                                    
< td  width ="70%"  height ="22" >
                                                                        
< input  type ="file"  name ="attachFile"  size ="40"
                                                                            required class
="input" >
                                                                        
< font  color ="red" > * </ font >
                                                                    
</ td >
                                                                
</ tr >
                                                                
< tr  bgcolor ="#F9EACA" >
                                                                    
< td  colspan ="6"  height ="22" >
                                                                        
< table  width ="100%"  border ="0"  cellspacing ="0"
                                                                            cellpadding
="0" >
                                                                            
< tr >
                                                                                
< td  align ="center" >
                                                                                    
< input  type ="Button"  value ="增  加"
                                                                                        onclick
="button_validate(this.form)"  class =input  />
                                                                                    
&nbsp;&nbsp;&nbsp;
                                                                                    
< input  type ="reset"  name ="reset"  value ="清  空"
                                                                                        class
="input" >
                                                                                
</ td >
                                                                            
</ tr >
                                                                        
</ table >
                                                                    
</ td >
                                                                
</ tr >
                                                            
</ table >
                                                        
</ form >
public  NodeAttach evaluate()  throws  FileNotFoundException, IOException 
    NodeAttach na 
= new NodeAttach();    
    
int maxPostSize = 3 * 5 * 1024 * 1024;    
    MultipartRequest mr 
= new MultipartRequest(ActionContext    
            .getActionContext().getRequest(), 
"D:/", maxPostSize, "gb2312");   
    
// 输出反馈信息   
    Enumeration files = mr.getFileNames();   
    
while (files.hasMoreElements()) {   
        String filePath 
= (String) files.nextElement();   
        System.out.println(
"filePath:" + filePath);   
        File file 
= mr.getFile(filePath);   
        
if (file != null{   
            String fileName 
= file.getName();   
            
// 创建输入数据流   
            FileInputStream fis = new FileInputStream(file);   
            
// 创建输出数据流   
            String newFileName = System.currentTimeMillis() + "."   
                    
+ FileU.getFilePostfix(fileName);   
            FileOutputStream fos 
= new FileOutputStream(getSaveDir() + "/"    
                    
+ newFileName);    
            
int bytesRead = 0;    
            
byte[] buffer = new byte[8192];    
            
while ((bytesRead = fis.read(buffer, 0, buffer.length)) != -1{    
                fos.write(buffer, 
0, bytesRead);    
            }
    
            na.setAttachFile(newFileName);    
            na.setAttachName(fileName);    
            na.setAttachSize((
int) file.length());    
            na.setAttachType(mr.getContentType(filePath));    
        }
    
    }
    
    
return na;    
}
  
  异常:
java.io.IOException: Corrupt form data: premature ending    
    at com.oreilly.servlet.multipart.MultipartParser.(MultipartParser.java:
205 )    
    at com.oreilly.servlet.MultipartRequest.(MultipartRequest.java:
222 )    
    at com.oreilly.servlet.MultipartRequest.(MultipartRequest.java:
173 )    
    at com.chinafi.node_attach.NodeAttachForm.evaluate(NodeAttachForm.java:
159 )    
    at com.chinafi.node_attach.AddNodeAttach.addNodeAttach(AddNodeAttach.java:
31 )    
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)    
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)    
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)    
    at java.lang.reflect.Method.invoke(Unknown Source)    
    at org.apache.struts.beanaction.ActionInvoker.invoke(ActionInvoker.java:
16 )    
    at org.apache.struts.beanaction.DefaultActionInterceptor.intercept(DefaultActionInterceptor.java:
5 )    
    at org.apache.struts.beanaction.BeanAction.execute(BeanAction.java:
246 )    
    at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:
431 )    
    at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:
236 )    
    at org.apache.struts.action.ActionServlet.process(ActionServlet.java:
1196 )    
    at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:
432 )    
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:
710 )    
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:
803 )    
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:
290 )    
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:
206 )    
    at com.chinafi.filter.GlobalFilter.doFilter(GlobalFilter.java:
25 )    
    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:
230 )    
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:
175 )    
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:
128 )    
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:
104 )    
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:
109 )    
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:
261 )    
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:
844 )    
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:
581 )    
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:
447 )    
    at java.lang.Thread.run(Unknown Source)
评论 18
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值