我正在使用带有 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/