当尝试上传超过2MB的文件或提交大型表单时,Apache Tomcat默认限制HTTP POST请求大小为2MB,导致'Post data too big'错误。解决办法是在server.xml中修改<Connector>元素,通过添加'maxPostSize'属性并设定更大值(以字节为单位)来增加限制,或者将其设为0禁用检查。
java web开发当中,使用apache tomcat作为服务器,使用POST请求数据时,可能会出现:Post too large...的情况,错误信息:Parameters were not parsed because the size of the posted data was too big. Use the maxPostSize attribute of the connector to resolve this if the application should accept large POSTs.
2.问题原因
Q: In Tomcat, I got a "Post data too big" error.
A: Apache Tomcat by default sets a limit on the maximum size of HTTP POST requests it accepts. In Tomcat 5, this limit is set to 2097152 (2 Mb). When you try to upload files or post forms that are larger than 2 MB, this error can occur.
The solution is to reconfigure Tomcat to accept larger POST requests, either by increasing the limit, or by disabling it. This can be done by editing Tomcat's server.xml. In the <Connector> element, add an attribute "maxPostSize" and set a larger value (in bytes) to increase the limit. Setting it to 0 will disable the size check.
网上解释是:As I understand it, Tomcat only enforces that limit if the content type is application/x-www-form-urlencoded. For multiparts you'll have to read the stream yourself and enforce the limit yourself. A great tool for working with multipart data is Apache FileUpload.