An illegal character error was reported when the springboot background controller received array parameters.

1. In the development process encountered the need to receive array parameters, found a lot of methods on the Internet or reported the problem of illegal characters, I urge you to solve the problem.

2. Since I am using STS and embedded tomcat9, I have tried to configure the tomcat file

3. Related codes

(1)
java.lang.IllegalArgumentException: Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986
at org.apache.coyote.http11.Http11InputBuffer.parseRequestLine(Http11InputBuffer.java:479) ~[tomcat-embed-core-8.5.34.jar:8.5.34]

(2)postmanurl
http://192.168.0.182:8088/Artilce/batchDelete?arrs[0]=1&arrs[1]=2

(3)controller
@RequestMapping(value="/batchDelete",method=RequestMethod.POST)
public boolean batchDelete(@RequestParam(value="arrs[]")Integer [] arrs) {                        
    for(int i=0;i<arrs.length;iPP) {
        System.out.println(arrs[i].toString());
    }        
    return true;
}

4. Ask the bosses to answer their doubts

May.19,2022

For

array, just pass the parameter with the same name, which is similar to the form you said:

@RequestParam(value="arrs[]")Integer [] arrs)

change it to the following:

@RequestParam(value="arrs") Integer[] arrs)

write as:

when passing parameters
arrs=1&arrs=2&arrs=3

cause of the problem:
this problem is a new feature in the higher version of tomcat: access parsing is carried out strictly according to the RFC3986 specification, while the RFC3986 specification defines that Url can only contain English letters (a-zA-Z), numbers (0-9),-_. ~ 4 special characters and all reserved characters (the following characters are specified as reserved characters in RFC3986:! *'() : @ & = + $, /?-sharp [])

solution:
1. In conf/catalina.properties, find the last comment line # tomcat.util.http.parser.HttpParser.requestTargetAllow= |, change it to tomcat.util.http.parser.HttpParser.requestTargetAllow= | [], which means that [] is released

.

2, instead of passing parameters in this way, we use the traditional parameter splicing form, a _

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1c20df1-3353a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1c20df1-3353a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?