开发者社区> 问答> 正文

struts2文件上传?报错

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>



展开
收起
爱吃鱼的程序员 2020-06-09 12:41:16 587 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    xml配置里写的上限好象只管到2m再大要写到struts.properties里面
    试了,还是没有用哦,struts.xml文件配置上传文件总大小还是可以的!springmvc劝降师还有30秒到达战场回复<aclass='referer'target='_blank'>@Jack_Q111:我记得tomcat的配置里面好像有最大上传文件大小还是连接超时时间,设置下这个就行了??设置大一点然后日志级别调debug

    2020-06-09 12:41:34
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载