Java 在struts2中使用execandwait拦截器进行多文件上载

Java 在struts2中使用execandwait拦截器进行多文件上载,java,file-upload,struts2,interceptor,struts2-interceptors,Java,File Upload,Struts2,Interceptor,Struts2 Interceptors,我正在尝试使用ExecuteAndWait拦截器上载多个文件。我已经完成了文件上传部分,但当我使用execAndwait时,出现了以下错误 java.io.FileNotFoundException: C:\Users\hp\AppData\Roaming\NetBeans\8.0.2\config\GF\u 4.1\domain1\generated\jsp\FileUpload\upload\u 454f573a\u 3a8d\u 4e15\u ba96\u aa9cb6f4486f\u 0

我正在尝试使用ExecuteAndWait拦截器上载多个文件。我已经完成了文件上传部分,但当我使用execAndwait时,出现了以下错误

java.io.FileNotFoundException: C:\Users\hp\AppData\Roaming\NetBeans\8.0.2\config\GF\u 4.1\domain1\generated\jsp\FileUpload\upload\u 454f573a\u 3a8d\u 4e15\u ba96\u aa9cb6f4486f\u 00000002.tmp (系统找不到指定的文件)

struts.xml


1000
50
result.jsp
wait.jsp
无效的\u token.jsp
index.jsp
行动

包文件包;
导入com.opensymphony.xwork2.ActionSupport;
导入java.io.File;
导入java.io.FileInputStream;
导入java.io.FileNotFoundException;
导入java.io.FileOutputStream;
导入java.io.IOException;
导入java.sql.SQLException;
导入javax.servlet.http.HttpServletRequest;
导入org.apache.struts2.interceptor.ServletRequestAware;
/**
*
*@author hp
*/
公共类文件上传扩展ActionSupport实现ServletRequestAware{
公共文件bean getFb(){
返回fb;
}
公共void setFb(FileBean fb){
this.fb=fb;
}
FileBean fb;
专用HttpServletRequest高铁;
公共HttpServletRequest getHsr(){
返回高铁;
}
公共无效设置hsr(HttpServletRequest hsr){
本节中,hsr=高铁;
}
FileDAO-fd;
公共文件dao getFd(){
返回fd;
}
公共void setFd(FileDAO fd){
this.fd=fd;
}
公共字符串execute()抛出FileNotFoundException、IOException、,
ClassNotFoundException,SQLException{
字符串filepath=hsr.getServletContext().getRealPath(“/”).concat(“文件”);
//字符串filepath1=hsr.getSession().getServletContext().getRealPath(“/”);
System.out.println(“图像位置:“+filepath”);
字符串doc=fb.getFile().getName().replace(“.tmp”、“.jpg”);
字符串filedb=filepath+“\\”+doc;
fb.setFiledb(doc);
字符串imgpath=hsr.getServletContext().getRealPath(“/”).concat(“图像”);
字符串img=fb.getImage().getName().replace(“.tmp”,“.jpg”);
字符串imagedb=imgpath+“\\”+img;
//字符串filedb2=doc;
fb.setImagedb(img);
System.out.print(“文件db:+fb.getFiledb());
FileInputStream fin=新的FileInputStream(fb.getFile());
FileOutputStream os=新的FileOutputStream(filedb);
int i=0;
而((i=fin.read())!=-1){
os.write(i);
}  
os.close();
FileInputStream fin1=新的FileInputStream(fb.getImage());
FileOutputStream os1=新的FileOutputStream(imagedb);
int j=0;
而((j=fin1.read())!=-1){
os1.write(j);
} 
os1.close();
fd=newfiledao();
setFd(fd);
if(fd.fileupload(fb.equals)(“fileupload”)){
返回“ok”;
}
返回“错误”;
}
@凌驾
公共无效设置ServletRequest(HttpServletRequest hsr){
这个。高铁=高铁;
}
}
wait.jsp


JSP页面
L O A D I N G。。。。。。!!

注意:我发现我的代码只接受一个文件或图像上传。

您的图像上传代码完全避免了Struts2约定。在Struts2中,上传多个文件要容易得多。当你让它以正确的方式工作时,试着添加execAndWait。@Andrea-我已经提到,除了实现execAndWait,我在上传多个文件时没有任何问题。你提到过,但是我告诉你,你是以一种非常奇怪、错误和没有效率的方式进行的。如果您现在不更改它,您也将在下一个项目中使用这种方式,查看您的代码的同事将无法立即处理它,也无法高效地处理它。只要正确使用它,不管它是否有效。遵循最佳实践(或者至少是……实践):|