Can not post form with many (over 256) values

时光总嘲笑我的痴心妄想 提交于 2019-12-05 18:07:38

问题


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"]

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)

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


回答1:


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);
}

Check this thread in Spring forum, also in the official documentation here.



来源:https://stackoverflow.com/questions/28811498/can-not-post-form-with-many-over-256-values

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!