形式太大例外

问题描述 投票:27回答:17

当我使用post请求发送大文件时,系统显示异常:

java.lang.IllegalStateException: Form too large1105723>200000
at org.mortbay.jetty.Request.extractParameters(Request.java:1404)
at org.mortbay.jetty.Request.getParameter(Request.java:749)......

当我在谷歌搜索帮助时,他们会提供一些帮助,例如webappcontext.setMaxFormContentSize(5000000);

我正在使用此代码但问题仍未解决

我也使用代码jettyServer.setAttribute("org.mortbay.jetty.Request.maxFormContentSize", 5000000);

但没有结果

注意: - 我正在使用Jetty-6.1.0

java jetty
17个回答
34
投票

尝试通过jetty.xml设置系统属性

    <Call class="java.lang.System" name="setProperty">
      <Arg>org.mortbay.jetty.Request.maxFormContentSize</Arg>
      <Arg>500000</Arg>
    </Call>

好的,你可以从你的网络应用程序配置它

在Web应用程序中添加WEB-INF / jetty-web.xml文件,并在该文件中配置参数:

  <?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">600000</Set>
  </Configure>

Document

版本7或更高版本

从版本7开始,Jetty的类已经转移到另一个包中。你必须用org.mortbay...替换org.eclipse...(感谢David的评论)。


1
投票

我使用jetty 9.2.3.v20140905,我修复了问题使用如下:

  • 配置pom.xml

<plugin>
  <groupId>org.eclipse.jetty</groupId>
  <artifactId>jetty-maven-plugin</artifactId>
  <version>9.2.3.v20140905</version>
  <configuration>
    <jettyXml>
      src/main/resources/jetty/jetty.xml
    </jettyXml>
  </configuration>
</plugin>
  • 配置jetty.xml

<Configure id="Server" class="org.eclipse.jetty.server.Server">
  <Call name="setAttribute">
    <Arg>org.eclipse.jetty.server.Request.maxFormContentSize</Arg>
    <Arg>-1</Arg>
  </Call>
</Configure>

0
投票

可能是因为版本7以来Jetty的变化,但我只有这样的成功:

在jetty-web.xml中,将下面的内容添加到Server对象中(1000000是一个示例大小,obv)

<Call name="setAttribute">
      <Arg>org.eclipse.jetty.server.Request.maxFormContentSize</Arg>
      <Arg>1000000</Arg>
</Call>

完整文件可能看起来像我的

<Configure id="Server" class="org.eclipse.jetty.server.Server">
    <Call name="setAttribute">
      <Arg>org.eclipse.jetty.server.Request.maxFormContentSize</Arg>
      <Arg>1000000</Arg>
    </Call>

    <Ref id="DeploymentManager">
          <Call id="webappprovider" name="addAppProvider">
            <Arg>
(...)

ref http://wiki.eclipse.org/Jetty/Howto/Configure_Form_Size


0
投票

如果您从eclipse / spring运行,请将以下内容添加到vm参数-Dorg.mortbay.jetty.Request.maxFormContentSize = -1


0
投票

我在ActiveMQ上遇到了类似的问题所以我不得不编辑jetty.xml并添加

  <property name="maxFormContentSize" value="-1" /> 

到处理程序属性。

从:-

 <property name="handler">
 <bean id="sec" class="org.eclipse.jetty.server.handler.HandlerCollection">
 <property name="handlers">
 <list>
 <bean class="org.eclipse.jetty.webapp.WebAppContext">
  <property name="contextPath" value="/admin" /> 
  <property name="resourceBase" value="${activemq.home}/webapps/admin" /> 
  <property name="logUrlOnStart" value="true" /> 
  </bean>

 <property name="handler">
 <bean id="sec" class="org.eclipse.jetty.server.handler.HandlerCollection">
 <property name="handlers">
 <list>
 <bean class="org.eclipse.jetty.webapp.WebAppContext">
  <property name="contextPath" value="/admin" /> 
  <property name="resourceBase" value="${activemq.home}/webapps/admin" /> 
  <property name="logUrlOnStart" value="true" /> 
  <property name="maxFormContentSize" value="-1" /> 
  </bean>

0
投票

通过添加命令行参数启动jenkins -Dorg.eclipse.jetty.server.Request.maxFormContentSize = 500000

即java -Dorg.eclipse.jetty.server.Request.maxFormContentSize = 500000 -jar jenkins.war


0
投票

如果您在嵌入模式下使用jetty,请尝试此操作。

    ServletContextHandler servletHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
    servletHandler.setMaxFormContentSize(1024*1024*1024);//size you want to allow.

0
投票

我使用Spring启动并在application.properties中设置server.jetty.max-http-post-size: maxSize来修复它。

server.jetty.max-http-post-size: 500000

0
投票

ActiveMQ:

这里的问题是JetM,ActiveMQ就是基于它的。你可以在这里找到更多细节,documentation

解决方案是在apache-activemq-5.9.0/bin/win64/wrapper.conf文件中,在b之后添加以下行a(参见下文)。

  • a:wrapper.java.additional.16=-Dorg.eclipse.jetty.server.Request.maxFormContentSize=1000000
  • b:wrapper.java.additional.15=-Djava.security.auth.login.config=%ACTIVEMQ_CONF%/login.config

如果您在32位计算机上运行,​​请在apache-activemq-5.9.0/bin/win32/wrapper.conf中添加相同的行。

快乐编码..


10
投票
import org.mortbay.jetty.Server;
//... other code here...//
int port = 8080;
Server server = new Server(port);
server.setAttribute("org.mortbay.jetty.Request.maxFormContentSize", -1);

这段代码适用于我正在使用的jetty 6.0.2。 大小“-1”表示表单没有限制我试图发布一个大的20,000,000字节的表单,我没有问题。 对于Jetty(jetty 7)的eclipse版本,您必须使用以下代码:

import org.eclipse.jetty.server.Server;
//... other code here...//
int port = 8080;
Server server = new Server(port);
server.setAttribute("org.eclipse.jetty.server.Request.maxFormContentSize", -1);

5
投票

不幸的是,我无法对jetty.xml进行任何更改,所以我只是设置一些选项来调整maxFormContentSize,如下所示:

JVM_OPTS="$JVM_OPTS -Dorg.eclipse.jetty.server.Request.maxFormContentSize=5000000"

这存在于我们用于启动Solr实例的shell脚本中。


4
投票

有关表单大小的更多文档:http://wiki.eclipse.org/Jetty/Howto/Configure_Form_Size


3
投票

我也遇到了这个问题(在另一个应用程序中运行Jetty,所以我没有使用jetty.xml)。

我在setMaxFormContentSize类上使用了ContextHandler方法,它修复了“形式太大”的异常。 (有关创建/使用上下文处理程序的示例,请参阅http://wiki.eclipse.org/Jetty/Tutorial/Embedding_Jetty#Setting_a_ServletContext)。


2
投票
webappcontext.getServletContext().getContextHandler() .setMaxFormContentSize(10000000);

2
投票
            <!-- Development Jetty -->
        <plugin>
            <groupId>org.mortbay.jetty</groupId>
            <artifactId>jetty-maven-plugin</artifactId>
            <version>8.1.8.v20121106</version>
            <configuration>
                <scanIntervalSeconds>1</scanIntervalSeconds>
                <webApp>
                    <contextPath>/${project.build.finalName}</contextPath>
                </webApp>
                <systemProperties>
                    <systemProperty>
                        <name>org.eclipse.jetty.server.Request.maxFormContentSize</name>
                        <value>10485760</value>
                    </systemProperty>
                </systemProperties>
            </configuration>
        </plugin>

在maven插件中为jetty 8工作


1
投票

根据您使用的Jetty版本的使用年限(在我的案例中,在Eclipse Equinox中嵌入了jetty-5.1.14),也可能是属性需要是org.mortbay.http.HttpRequest.maxFormContentSize

来自:org.mortbay.http.HttpRequest

/**
 * Max size of the form content. Limits the size of the data a client can push at the server.
 * Set via the org.mortbay.http.HttpRequest.maxContentSize system property.
 */
public static int __maxFormContentSize = Integer.getInteger(
        "org.mortbay.http.HttpRequest.maxFormContentSize", 200000).intValue();

因此,您需要在启动时在应用程序中执行以下操作来设置值:

System.setProperty("org.mortbay.http.HttpRequest.maxFormContentSize", "10000000");

1
投票

以上解决方案均不适合我,

因此,为了完成这项工作,我在创建服务器之前设置系统属性,而不是将其设置为服务器属性

 System.setProperty("org.eclipse.jetty.server.Request.maxFormContentSize", "500000000");

 Server server = ServerFactory.createServer(host, port, contextPath, war);
© www.soinside.com 2019 - 2024. All rights reserved.