SpringBoot 2.1. 3 Modify tomcat parameter support request special symbol problem

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

Recently, I encountered a problem. For example, in GET request, key and value have special symbols, and the request will report an error. See the following URL:

http://xxx.xxx.xxx:8081/aaa?key1=val1 & a.[].id=123 & b=a[1]

Now, let's enter the boot startup class and add the following code:


public class DemoApp {
  public static void main(String[] args) {
      SpringApplication.run(DemoApp.class, args);
  }
  @Bean
  public TomcatServletWebServerFactory webServerFactory() {
     TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();
     factory.addConnectorCustomizers(new TomcatConnectorCustomizer() {
              @Override
              public void customize(Connector connector) {
                  connector.setProperty("relaxedPathChars", "\"<>[\\]^`{|}");
                  connector.setProperty("relaxedQueryChars", "\"<>[\\]^`{|}");
               }
      });
      return factory;
  }
}

Summarize

Above is the site introduced to you SpringBoot2.1. 3 modified tomcat parameters support request for special symbols, if you have any questions please leave me a message, this site will reply to you in time. Thank you very much for your support to this site!


Related articles: