Setting tomcat through spring boot solves the problem of post parameter restriction

  • 2021-07-24 10:55:31
  • OfStack

Today, the pictures are transmitted with base64 string and POST method. When the front end is transmitted, it always crashes inexplicably. I searched the Internet for half a day and thought that the file size was limited, but I received the string, not the file, so I continued to search. The original post itself has no parameter size limit, but tomcat is limited, so the solution is as follows:

1. External tomcat

This is simple. Add or modify this sentence directly in server. xml:


<Connector port="8080" protocol="HTTP/1.1" 
 connectionTimeout="2000" 
 redirectPort="8443" 
 URIEncoding="UTF-8"
 maxThreads="3000"
 compression="on" compressableMimeType="text/html,text/xml" 
 maxPostSize="0" 
/>

Yes, it is to modify here maxPostSize The default value is 1024. If you change it to 0, you can not limit the size

2. To use tomcat that comes with spring boot, add this sentence to application. properties:

server.tomcat.max-http-post-size=0

I searched for a big push on the Internet before, and the most is: spring.http.multipart.file-size But instead of setting the file size, it is setting the post parameter string size, and these methods are no longer recommended.

Important! ! ! After modifying the configuration, the partner who did not do hot deployment should remember to restart the server, and the partner who did hot deployment should remember to restart 1 and then test again if it is invalid.

Summarize

The above is introduced by this site to solve the problem of post parameter restriction by setting tomcat through spring boot. If you have any questions, please leave me a message and this site will reply to you in time. Thank you very much for your support to this site!


Related articles: