Tomcat8.5:不存在必需的字符串参数“...”

Tomcat 8.5: Required String parameter '...' is not present

在从 Tomcat 7.0.50 升级到 Tomcat 8.5.15 期间,它停止识别我的一种方法的 POST 参数之一:我得到的而不是正常的响应是这条消息

HTTP Status [400] – [Bad Request]

Type Status Report

Message Required String parameter 'password' is not present

Description The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).

Apache Tomcat/8.5.15

方法签名是:

@RequestMapping(value = "/login", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> login(
    @RequestParam("password") String passwordHash,
    @RequestParam("username") String loginName,
    @RequestParam(value = "clientId", required = false) String clientId,
    HttpServletRequest request,
    HttpServletResponse response)
    throws NoSuchAlgorithmException {//...

我已经从请求中捕获了流量,如您所见,password POST 参数包含在 POST x-www-form-urlencoded 参数中:

POST http://<masked>/Server/user/login HTTP/1.1
Host: <masked>
Connection: keep-alive
Content-Length: 270
Origin: http://<masked>
X-Requested-With: ShockwaveFlash/26.0.0.131
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.104 Safari/537.36
Content-Type: application/x-www-form-urlencoded
Accept: */*
Referer: http://<masked>
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.8,ru;q=0.6,he;q=0.4
Cookie: <masked>

noremember=true&password=C9TUq%2BYMIbeoW%2ByfoSCt9QJoOnmSGR8BqRKdOjufjE7%2FoHUDpPf3FHSvCUbZu4EBSKkJV2ryGs1Q77D7SFbBKZZ3joWcMTN6aTsgmPsOdW0Md1qcOkB4w4L3F53XZRlKUp2RaxCjoE0AIr%2B0WLomGFSrn8u8iTf2p4Z7Mo6ZKPA%3D&username=test%40example%2Ecom&clientId=1858390758%2E1481631908

奇怪的是它在 Tomcat 7

下完美运行

这有什么帮助?

终于找到原因了。 在 Tomcat 7.0.50 的旧配置中,server.xmlConnector 中有 maxPostSize="0" 参数,我已将其复制到新配置中,但自从 Tomcat version 7.0.63 maxPostSize="0" 不是无限的意思,而是"empty",所以应该用maxPostSize="-1"

The meaning of the value zero for the maxPostSize has also been changed to mean a limit of zero rather than no limit to align it with maxSavePostSize and to be more intuitive. (markt)

Tomcat 7.0.63 changelog