List items = upload.parseRequest(request),items为空
jsp的form里面这样写的:
<html:form method="post" action="/t04_report/t04_report_list.do" enctype="multipart/form-data">
Action里面这样写的:
private ActionForward performImportReports(ActionMapping actionMapping,
ActionForm actionForm, HttpServletRequest request,
HttpServletResponse response) {
DiskFileItemFactory factory = new DiskFileItemFactory();
// 设置内存缓冲区,超过后写入临时文件
factory.setSizeThreshold(10240000);
// 设置临时文件存储位置
String base = this.getServletContext().getRealPath("/")+"files";
System.out.println("--------base----------------->"+base);
File file = new File(base);
System.out.println("------------>"+file.exists());
if(!file.exists()){
file.mkdirs();
}
factory.setRepository(file);
ServletFileUpload upload = new ServletFileUpload(factory);
// 设置单个文件的最大上传值
upload.setFileSizeMax(10002400000l);
// 设置整个request的最大值
upload.setSizeMax(10002400000l);
upload.setHeaderEncoding("gb2312");
try {
List<?> items = upload.parseRequest(request);
System.out.println("itemsSize--------------->"+items.size());//值为0,纠结啊。。。
FileItem item = null;
String fileName = null;
for (int i = 0 ;i < items.size(); i++){
item = (FileItem) items.get(i);
fileName = base + File.separator + item.getName();
System.out.println("------------------>"+item.getFieldName());
// 保存文件
System.out.println("--------fileName-------->"+fileName);
if (!item.isFormField() && item.getName().length() > 0) {
item.write(new File(fileName));
}
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
List items = upload.parseRequest(request),items为空,不知道怎么办了,求大哥们帮忙解决啊!
------解决方案--------------------在status2 的配置文件里加上
<bean type= "org.apache.struts2.dispatcher.multipart.MultiPartRequest"
name= "myRequestParser" class= "com.icf.common.base.actions.RequestParseWrapper"
scope= "default" optional= "true " />
<constant name= "struts.multipart.handler" value= "myRequestParser" />
class
public class RequestParseWrapper extends JakartaMultiPartRequest {
publicvoid parse(HttpServletRequest servletRequest, String saveDir)throws
IOException{
}
}
这样就可以得到request里的item
------解决方案--------------------同样错误,纠结中~
------解决方案--------------------enctype="multipart/form-data"去掉就可以了
------解决方案--------------------public void uploadFile(HttpServletRequest request, HttpServletResponse response)