Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can not post form with many (over 256) values

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.

like image 226
svenhornberg Avatar asked Mar 02 '15 13:03

svenhornberg


1 Answers

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.

like image 85
Leandro Carracedo Avatar answered Oct 20 '22 01:10

Leandro Carracedo