Java 表格太大异常

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3861455/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 05:56:30  来源:igfitidea点击:

Form too Large Exception

javajetty

提问by Narendra nnvd

When I send a large file using a post request the system shows an exception:

当我使用 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)......

When I search help for this in Google they give some help e.g., webappcontext.setMaxFormContentSize(5000000);

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

I am using this code but the problem is not solved

我正在使用此代码但问题没有解决

Also I am using the code jettyServer.setAttribute("org.mortbay.jetty.Request.maxFormContentSize", 5000000);

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

But no result

但是没有结果

Note:-I am using Jetty-6.1.0

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

回答by Jigar Joshi

Try setting System properties via jetty.xml

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

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

ok you can configure it from your web app

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

Add WEB-INF/jetty-web.xml file in your web application and configure the parameter in that file:

在您的 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

文档

Version 7 or Higher

版本 7 或更高版本

Since version 7, Jetty's classes have moved to a different package. You must replace org.mortbay...with org.eclipse...(Thanks to David for his comment).

自第 7 版起,Jetty 的类已移至不同的包中。您必须替换org.mortbay...org.eclipse...(感谢大卫的评论)。

回答by Ash

I came across this problem too (running Jetty embedded in another application, so I'm not using jetty.xml).

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

I used the setMaxFormContentSizemethod on the ContextHandlerclass, which fixed the "form too large" exception. (See http://wiki.eclipse.org/Jetty/Tutorial/Embedding_Jetty#Setting_a_ServletContextfor an example of creating/using a context handler).

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

回答by Narendra nnvd

webappcontext.getServletContext().getContextHandler() .setMaxFormContentSize(10000000);

回答by volni

回答by Attila Andrei Aknai

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

This code works on jetty 6.0.2 which I'm using.
The size of "-1" means the form has no limit I tryed to post a form large 20,000,000 bytes and I had no problem.
For eclipse releases of Jetty(jetty 7) you have to use the following code:

此代码适用于我正在使用的 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);

回答by Timmy Chiu

            <!-- 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>

Work for jetty 8 in maven plugin

在 Maven 插件中为 jetty 8 工作

回答by Christoph

Depending on how old your Jetty Version is you are using (in my case jetty-5.1.14 embedded in Eclipse Equinox), it also could be that the property needs to be org.mortbay.http.HttpRequest.maxFormContentSize

根据您使用的 Jetty 版本的年龄(在我的情况下,嵌入在 Eclipse Equinox 中的 jetty-5.1.14),也可能是该属性需要为org.mortbay.http.HttpRequest.maxFormContentSize

From: org.mortbay.http.HttpRequest

来自: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();

So you need to do something like this in your application on startup to set the value:

所以你需要在启动时在你的应用程序中做这样的事情来设置值:

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

回答by jsh

Possibly because of changes in Jetty since version 7, but I only had success like so:

可能是因为自第 7 版以来 Jetty 发生了变化,但我只有这样的成功:

in jetty-web.xml, add the below to the Server object (1000000 is an example size, obv)

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

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

full file might look something like mine

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

<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

参考http://wiki.eclipse.org/Jetty/Howto/Configure_Form_Size

回答by NullPointerException

None of the above Solution worked for me ,

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

So in order to make this work I set the system property before creating the server, rather then setting it as server attribute

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

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

 Server server = ServerFactory.createServer(host, port, contextPath, war);

回答by seth

Unfortunately, I'm not able to make any changes to jetty.xml, so instead I simply set some options to adjust the maxFormContentSize like so:

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

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

This exists in the shell script that we use to launch our instance of Solr.

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