tomcat配置上传大小

2024-09-09 09:11:58 浏览数 (1)

POST数据过大时,JAVA后端会无法收到,收到的数据为null,导致程序异常。此时需要进行配置修改,tomcat的版本大于等于8,设置maxPostSize=“104857600” 表示post参数最大100MB;设置maxPostSize=“-1” 表示无限大(设置为负数即可);设置maxPostSize=“0” 表示不允许接收。不设置表示默认大小为2MB

需要在节点增加该配置即可:

代码语言:xml复制
<Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443"
               maxParameterCount="1000"
                maxPostSize="-1"
               />

maxPostSize 的单位为 byte。官方文档注释如下:

The maximum size in bytes of the POST which will be handled by the container FORM URL parameter parsing. The limit can be disabled by setting this attribute to a value less than zero. If not specified, this attribute is set to 2097152 (2 megabytes). Note that the FailedRequestFilter can be used to reject requests that exceed this limit.

0 人点赞