无法发布具有许多(超过256个)值的表单 [英] Can not post form with many (over 256) values
问题描述
我在Thymeleaf上使用Spring Boot 1.2.2. 我的问题是我尝试以表格形式发布一长列的项目(一些标签,一个复选框),但无法执行列表中的许多项目. (我测试了小列表,但效果很好.)
I am using Spring Boot 1.2.2 with Thymeleaf. My Problem is I try to post a long list of Items (some labels, one checkbox) in a form, which cant be perform so many items of my list. (I tested small lists and it worked.)
首先,我使用码头,但遇到了一个错误,提示:
First I used jetty but got an error, which says:
java.lang.IllegalStateException: Form too many keys
at org.eclipse.jetty.util.UrlEncoded.decodeUtf8To(UrlEncoded.java:526)
我搜索并看到了此帖子.结果,我添加了
I searched and saw this post. As the result I added
applicationDefaultJvmArgs = ["-Dorg.eclipse.jetty.server.Request.maxFormKeys=8000"]
到我的gradle.build,但是没有成功.结果,我切换到Tomcat,它再次失败.错误消息是:
to my gradle.build, but it didnt work out. As the result I switched to Tomcat and it fails again. The errormessage is:
java.lang.IndexOutOfBoundsException: Index: 256, Size: 256
at java.util.ArrayList.rangeCheck(ArrayList.java:635)
看起来只能执行256个条目.我有大约500个条目.因此,我认为增加maxhttpheadersize会有所帮助,并将此行添加到我的application.properties:
looks like it can only perform 256 entries. I have about 500 entries. So I thought increasing the maxhttpheadersize would help and added this line to my application.properties:
server.tomcat.max-http-header-size=-1
(-1为无限制)我以Thymeleaf形式设置method ="post".还有其他方法可以增加256个限制吗?我不想对我的结果进行分页.感谢您的帮助.
(-1 as no limit) I set method="post" in my Thymeleaf form. Any other way to increase the 256 limit ? I dont want to paginate my result. Thanks for any help.
推荐答案
我认为这与Spring中的AutoGrowCollectionLimit
有关,请尝试在控制器中包括此代码以增加它:
I think this is related to AutoGrowCollectionLimit
in Spring, try to include this code in your controller in order to increase it:
@InitBinder
public void initBinder(WebDataBinder binder) {
binder.setAutoGrowCollectionLimit(768);
}
在Spring论坛中检查此线程,也在官方文档中
Check this thread in Spring forum, also in the official documentation here.
这篇关于无法发布具有许多(超过256个)值的表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!