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

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

java.lang.IllegalStateException: Form too large270468>200000
    at org.mortbay.jetty.Request.extractParameters(Request.java:1561)
    at org.mortbay.jetty.Request.getParameterMap(Request.java:870)
    at org.apache.struts2.dispatcher.Dispatcher.createContextMap(Dispatcher.java:528)
    at org.apache.struts2.dispatcher.ng.PrepareOperations.createActionContext(PrepareOperations.java:78)
    at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareFilter.doFilter(StrutsPrepareFilter.java:74)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1212)
    at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:399)
    at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
    at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
    at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:766)
    at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:450)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at org.mortbay.jetty.Server.handle(Server.java:326)
    at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
    at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:945)
    at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:756)
    at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:218)
    at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
    at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:410)
    at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)

很明显是单个请求数据过大,Form too large>200000(200000即200000Byte约为2M),但异常是在什么地方抛出来的呢,经过一番研究,发现是Jetty插件报出的如下:

在\eclipse\plugins目录下,找到org.mortbay.jetty.server_6.1.23.v201012071420.jar包,扔进JD-GUI中,根据报错提示信息org.morbay.jetty.Request.extractParameters()方法中找到如下信息:

注意观察箭头所示部分,异常应该是这儿抛出来的,但maxFormContentSize值是从那里来的呢,依据this._context.getContextHandler().getMaxFormContentSize()这句提示,找到org.mortbay.jetty.handlerContextHandler.class类,结果发现该类中有如下一句,兴奋,默认值在此。

那么这个默认值是设置好的,如何修改呢,通过看Request类里的this._context.getContextHandler().getMaxFormContentSize()代码,继续追踪,该值应该是从WEB的入口获取的即web.xml,但是这个值如何传进去呢,经过网上的搜索与实践,可以在WEB-INF目录下新建一个jetty-web.xml文件,里面写如下内容,对maxFormContentSize重新赋值即可(Jetty6适用):

<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd">
<Configure id="WebAppContext" class="org.mortbay.jetty.webapp.WebAppContext">
     <Set name="maxFormContentSize" type="int">6000000</Set>
</Configure>  

重新启动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只需改下包的路径,完整配置文件如下:

<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd">
<Configure id="WebAppContext" class="org.mortbay.jetty.webapp.WebAppContext">
     <Set name="maxFormContentSize" type="int">6000000</Set>
</Configure>  

欧啦,大功告成!

本文转载自http://blog.csdn.net/shixing_11/article/details/6996236#

时间: 2024-09-30 19:33:42

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

Jetty错误: badMessage: java.lang.IllegalStateException: too much data after closed for [email&#160;protected]{r=2,c=false,a=IDLE,uri=}

最近用Jetty跑Spring MVC接收POST请求(POST中数据很大).出现数据无法获取到的问题.如: @RequestMapping(value = "/receive", method = RequestMethod.POST) public receive(String a,String b,String c) 其中a是从POST中获取,先前数据量小的时候,可以取到没有问题. 用抓包工具看,发现POST数据没发完就HTTP就返回了.这点很奇怪 调大下面的参数值: <S

java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState问题解决

(1)我用的是fragment,在onStop但是没有onDestroy的情况下切换(replace)fragment时报 java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState错误,出现问题原因,在于我使用了FragmentTransaction.commit,解决办法:使用FragmentTransaction.commitAllowingStateLoss就不会报错了 (2

使用printWrite 在jetty中报错 java.lang.IllegalStateException: STREAM

1 public void doFilter(ServletRequest request, ServletResponse response, 2 FilterChain chain) throws IOException, ServletException { 3 // TODO Auto-generated method stub 4 HttpServletRequest req=(HttpServletRequest)request; 5 HttpServletResponse res=

android 修改listview中adapter数据时抛出异常java.lang.IllegalStateException: The content of the adapter has changed but ListView did not receive a notification问题

近日在做项目时遇到非必现crush,具体异常信息为: // Short Msg: java.lang.IllegalStateException // Long Msg: java.lang.IllegalStateException: The content of the adapter has changed but ListView did not receive a notification. Make sure the content of your adapter is not mo

一个坑poi大数据量导入时的java.lang.IllegalStateException: Zip File is closed

本帖子没有答案,只是说一下坑,余下的自己决定. Caused by: java.lang.IllegalStateException: Zip File is closed at org.apache.poi3.openxml4j.util.ZipFileZipEntrySource.getEntries(ZipFileZipEntrySource.java:45) at org.apache.poi3.openxml4j.opc.ZipPackage.getPartsImpl(ZipPacka

使用RestTemplate时报错java.lang.IllegalStateException: No instances available for 127.0.0.1

我在RestTemplate的配置类里使用了 @LoadBalanced@Componentpublic class RestTemplateConfig { @Bean @LoadBalanced public RestTemplate restTemplate(){ return new RestTemplate(); }}或者 再调用@Autowiredprivate RestTemplate restTemplate;必须使用应用名作为代替ip:端口,http://127.0.0.1:8

批量下载的实现及java.lang.IllegalStateException异常

在工作流的一张表单里可能会有多个步骤上传附件,在用户的待办中往往会存在多条带有附件的任务,如果一一打开并且点击下载链接下载,不仅费时,而且繁琐,用户体验较差. OA系统采用的是FastDFS做为文件服务器,FastDFS的Java客户端提供了上传.下载等功能供调用. 在我之前的文章里对此有描述,目前已有的代码有对文件的批量上传功能,但下载的参数往往是针对单个文件.比如单个文件的下载方法如下: /**  * 文件下载  * @author chao.gao  * @date 2014-2-17 下

WARN::Committed before 500 Unable to show problem report:|java.lang.IllegalStateException

2015-01-06 18:23:17.160:WARN::Committed before 500 Unable to show problem report:|java.lang.IllegalStateException: STREAM||Class: org.mortbay.jetty.Response|File: Response.java|Method: getWriter|Line: 616 - org/mortbay/jetty/Response.java:616:-1 2015

java.lang.IllegalStateException

java.lang.IllegalStateExceptionorg.apache.catalina.connector.ResponseFacade.sendRedirect(ResponseFacade.java:423)经过分析.查看jdk文档终于找到解决的办法,在response.sendRedirect()方法后加return语句即可,如下:response.sendRedirect(login.jsp);return null;原因是:在程序中两次调用了response.sendRe