spring-boot - 无法发布具有许多(超过 256 个)值的表单

标签 spring-boot thymeleaf embedded-jetty embedded-tomcat-8

我正在使用带有 Thymeleaf 的 Spring Boot 1.2.2。
我的问题是我尝试在表单中发布一长串项目(一些标签,一个复选框),但无法执行我列表中的这么多项目。 (我测试了小列表并且它起作用了。)

首先我使用码头但得到一个错误,它说:

java.lang.IllegalStateException: Form too many keys
at org.eclipse.jetty.util.UrlEncoded.decodeUtf8To(UrlEncoded.java:526)

我搜索并看到了这个 post .结果我加了
applicationDefaultJvmArgs = ["-Dorg.eclipse.jetty.server.Request.maxFormKeys=8000"]

到我的 gradle.build,但没有成功。结果我切换到Tomcat,它又失败了。错误信息是:
java.lang.IndexOutOfBoundsException: Index: 256, Size: 256
at java.util.ArrayList.rangeCheck(ArrayList.java:635)

看起来它只能执行 256 个条目。我有大约 500 个条目。所以我认为增加 maxhttpheadersize 会有所帮助,并将这一行添加到我的 application.properties 中:
server.tomcat.max-http-header-size=-1

(-1 表示没有限制)我在 Thymeleaf 表单中设置了 method="post"。还有其他方法可以增加 256 限制吗?我不想对我的结果进行分页。谢谢你的帮助。

最佳答案

我认为这与AutoGrowCollectionLimit有关在 Spring 中,尝试将此代码包含在您的 Controller 中以增加它:

@InitBinder
public void initBinder(WebDataBinder binder) {
    binder.setAutoGrowCollectionLimit(768);
}

查询 this Spring 论坛中的线程,也在官方文档中 here .

关于spring-boot - 无法发布具有许多(超过 256 个)值的表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28811498/

相关文章:

spring-boot - 从 Grails 3 迁移到 Spring-Boot

java - 使用 Ajax 从 Spring Controller 加载 Modal 中的数据

java - 有没有办法在嵌入式 jetty 中以编程方式设置上下文参数?

eclipse-plugin - 将 jetty 输出打印到 Eclipse 控制台窗口

java - 如何通过 SparkJava 更改 Jetty 设置?/Form too Large Exception/org.eclipse.jetty.server.Request.maxFormContentSize

spring-boot - 为 Google Cloud Run 外部化应用程序配置

java - 覆盖配置文件中的 maven 依赖范围

mysql - SPRING BOOT手动War文件部署到Tomcat并重启服务器,不创建数据库

java - 即使表单字段留空,也会提交空字符串并在 Spring 中创建新实体

spring-mvc - Thymeleaf 模板解析器前缀与 Gradle