TOMCAT在POST方法提交参数丢失问题

摘自http://my.oschina.net/luckyi/blog/213209
昨天在解决一个BUG时发现一个奇怪的问题,一个AJAX提交数据在之前都是木有问题的,突然提交出错影响其他处理流程。

检查时发现页面处理数据较多,起初以为是提交顺序不正确修改后发现不是由此问题引起。于是删除掉一部分数据进行提交,较少数据能够提交成功。

恢复较多数据后跟踪提交FORM DATA ,发现数据是存在的,同时后台也未报其他错误。

随后设置Tomcat中POST方式提交数据大小:
maxPostSize="0"
修改后提交数据依然会出错,但给出了错误提示:
信息: More than the maximum number of request parameters (GET plus POST) for a single request ([10,000]) were detected. Any parameters beyond this limit have been ignored. To change this limit, set the maxParameterCount attribute on the Connector.

Note: further occurrences of this error will be logged at DEBUG level.

按照错误提示在在Connector 节点中加入maxParameterCount="-1",再进行测试便成功了。
<Connector executor="tomcatThreadPool"

               port="9080"

               protocol="HTTP/1.1"

                maxParameterCount="-1"

               connectionTimeout="20000"

               acceptCount="75"

               disableUploadTimeout="true"

               enableLookups="false"

               URIEncoding="UTF-8" />


maxParameterCount:

The maximum number of parameters (GET plus POST) which will be automatically parsed by the container. 10000 by default. A value of less than 0 means no limit.
查询网上资料了解到引起该问题是
由于Java中的哈希表实现上的漏洞,现如今因为Tomcat使用了哈希表来存储HTTP请求参数,因此也受此问题影响。

为此Tomcat实现了一个变通的做法,提供一个新的选项maxParameterCount用来限制但请求中最大的参数数量,该参数默认值是10000,这对多数应用程序来说已经足够,这个值也足够用来绕过JRE中的哈希表的bug。

如果你正在使用早期的Tomcat版本(Apache Tomcat 5.x,Apache Tomcat 6.x,Apache Tomcat 7.x),没有maxParameterCount属性,那么可以通过限制maxPostSize到10kb以下来解决这个问题。


也可以升级到5.5.35, 6.0.35或7.0.23及以上版本使用maxParameterCount属性进行处理。

你可能感兴趣的:(java,tomcat,jsp)