JSP使用FileUpload上传文件设置setSizeMax后连接被重置

今天在学习利用JSP+Servlet+FileUpload开发文件上传功能。在设置了上传文件最大限制为10M以后,选择了3M的pdf上传提交后连接被重置了。。。

 

 

我的代码:

//设置上传单个文件的大小的最大值,目前是设置为1024*1024字节,也就是1MB
        upload.setFileSizeMax(1024 * 1024);
        //设置上传文件总量的最大值,最大值=同时上传的多个文件的大小的最大值的和,目前设置为10MB
        upload.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

修改前:

<Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />

 

修改后:

<Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000" connectionUploadTimeout="36000000" disableUploadTimeout="false" maxSwallowSize="-1"
               redirectPort="8443" />

 

 

 

 

重启后测试正常!

 

 

 

 

 

 

 

 

 

 

 

 

posted @   一锤子技术员  阅读(28)  评论(0编辑  收藏  举报  
编辑推荐:
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 张高兴的大模型开发实战:(一)使用 Selenium 进行网页爬虫
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
点击右上角即可分享
微信分享提示