struts2在做文件上传是,当超过限制的上传文件总大小时,直接与服务器断开连接了,后台也没有报错,怎么回事啊?tomcat7.0的服务器,6.0试了也是这样。
package com.eg.action;
import java.io.File; import java.io.IOException; import java.util.List;
import org.apache.commons.io.FileUtils; import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionSupport;
public class FileuploadAction extends ActionSupport {
private List<File> upload;
private List<String> uploadContentType;
private List<String> uploadFileName;
public List<File> getUpload() {
return upload;
}
public void setUpload(List<File> upload) {
this.upload = upload;
}
public List<String> getUploadContentType() {
return uploadContentType;
}
public void setUploadContentType(List<String> uploadContentType) {
this.uploadContentType = uploadContentType;
}
public List<String> getUploadFileName() {
return uploadFileName;
}
public void setUploadFileName(List<String> uploadFileName) {
this.uploadFileName = uploadFileName;
}
@Override
public String execute() {
for (int i = 0; i <upload.size(); i++) {
System.out.println("上传的文件类型:" + uploadContentType.get(i));
System.out.println("上传的文件名:" + uploadFileName.get(i));
try {
FileUtils.copyFile(upload.get(i), new File(ServletActionContext
.getServletContext().getRealPath("/WEB-INF/uploads"),
uploadFileName.get(i)));
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
return null;
}
}
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" "http://struts.apache.org/dtds/struts-2.3.dtd"> <struts><!-- 限制上传的文件总大小为200M --> <constant name="struts.multipart.maxSize" value="209715200"></constant> <constant name="struts.custom.i18n.resources" value="message"></constant> <package name="default" namespace="/" extends="struts-default"> <action name="upload" class="com.eg.action.FileuploadAction"> <result name="input">/error.jsp</result> <interceptor-ref name="defaultStack"> <param name="fileUpload.maximumSize">20971520</param> <param name="fileUpload.allowedExtensions">txt,avi,doc,xml</param> </interceptor-ref> </action> </package> </struts>
xml配置里写的上限好象只管到2m再大要写到struts.properties里面
试了,还是没有用哦,struts.xml文件配置上传文件总大小还是可以的!springmvc劝降师还有30秒到达战场回复<aclass='referer'target='_blank'>@Jack_Q111:我记得tomcat的配置里面好像有最大上传文件大小还是连接超时时间,设置下这个就行了??设置大一点然后日志级别调debug
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。