读书人

Jetty提交数据时报java.lang.IllegalS

发布时间: 2012-06-26 10:04:14 作者: rapoo

Jetty提交数据时报java.lang.IllegalStateException: Form too large270468>200000问题解决

今天在使用Eclipse的Jetty插件做为服务器提交富文本编辑中的数据时,报如下异常:

重新启动web应用,再次提交数据,发现可以正常提交了,到此,问题圆满解决。

那么其它服务器有没有类似情况,答案当然是肯定的,如Tomcat,通过搜索找到了如下内容:

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.

意思是说,tomcat默认设置能接收HTTP POST请求的大小最大为2M,如果你的POST请求传递的数据大于2M,就会报这个错误.解决的办法是修改tomcat的配置文件$TOMCAT_HOME$/conf/server.xml,找到里面的<Connector>标签,在该标签中添加"maxPostSize"属性,将该属性值设置成你想要的最大值,单位是字节,如果你把这个值设置为0(maxPostSize="0"),tomcat将不再检查POST的大小.

本人测试环境如下:

Jetty版本:Run Jetty Run Feature1.2.2.1

Jetty对应的jar包版本:org.mortbay.jetty.server_6.1.23.v201012071420.jar

对于Jetty7只需改下包的路径,完整配置文件如下: