Spring MVC POST 参数无法绑定

Spring MVC 控制器,方法的参数突然绑定不上。

查看了相关的资料:这里这里,都是说与 Content-Type 属性有关。
但从代码看,一切正常,并没有网上描述的情况。
换了一台电脑后,发现一切又恢复正常。想到最近优化过 Tomcat 。于是
最终确定问题的原因是 Tomcat 优化参数

<Connector port="8080" 
           maxPostSize="0"
           ....
/>

其中问题是在 maxPostSize="0"上。
当去掉时,一切正常。

Tomcat 官方介绍

maxPostSize : 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 or equal to 0. If not specified, this attribute is set to 2097152 (2 megabytes).

大致意思是:maxPostSize 表示 post 参数的最大限制。如果设置为 0 或者 <0 则表示没有限制。

但是为什么设置为 0 时候,就没有办法传递参数了呢?

后来找到了 stackoverflow 上的一段说明:maxPostSize in tomcat’s configuration

The docs aren’t quite right. maxPostSize=0 results in a limit of zero. -1 is the correct value for no limit. I’ll get that fixed shortly.

大致意思:maxPostSize=0 导致 post 可传递的大小限制为 0 。正确表示没有限制应该设置为 -1 。

至此,应该是某些版本的 Tomcat 有此 Bug。至少确认 tomcat 8.5.11 有此问题。
maxPostSize 如果想要设置,可以设置为 -1。避免出现问题。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值