Can not post form with many (over 256) values
Asked Answered
G

1

15

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.

Gynous answered 2/3, 2015 at 13:53 Comment(1)
Just a quick comment. I am using Spring Boot 1.3.3 and when I set server.tomcat.max-http-header-size=0 it does not actually change the configuration. Stepping through the code, that means to use the default, which is 8192. I set it to a large value 65536 and that worked.Theone
M
22

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.

Muchness answered 3/3, 2015 at 0:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.