JSP使用FileUpload上传文件设置setSizeMax后连接被重置
今天在学习利用JSP+Servlet+FileUpload开发文件上传功能。在设置了上传文件最大限制为10M以后,选择了3M的pdf上传提交后连接被重置了。。。
我的代码:
//设置上传单个文件的大小的最大值,目前是设置为1024*1024字节,也就是1MBupload.setFileSizeMax(1024 * 1024);//设置上传文件总量的最大值,最大值=同时上传的多个文件的大小的最大值的和,目前设置为10MBupload.setSizeMax(1024 * 1024 * 10);
一头雾水,
后来在stackoverflow上找到了答案,这个和Tomcat默认设置有关,server.xml中有个重要参数
maxSwallowSize 默认为2M,改为-1表示无限制
maxSwallowSize
The maximum number of request body bytes (excluding transfer encoding overhead) that will be swallowed by Tomcat for an aborted upload. An aborted upload is when Tomcat knows that the request body is going to be ignored but the client still sends it. If Tomcat does not swallow the body the client is unlikely to see the response. If not specified the default of 2097152 (2 megabytes) will be used. A value of less than zero indicates that no limit should be enforced.
解决方案:
修改tomcat配置文件server.xml
修改前:
redirectPort="8443" />
修改后:
redirectPort="8443" />
重启后测试正常!
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
