The filter is added to the web, and there is still a solution to garbled characters

Generally speaking, if you add a filter to web.xml, it will not be garbled.

<!-- Set filter code-->
  <filter>
    <filter-name>encode</filter-name>
    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
    <init-param>
      <param-name>encoding</param-name>
      <param-value>UTF-8</param-value>
    </init-param>
  </filter>
  <filter-mapping>
    <filter-name>encode</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>

But sometimes it still messes up

First make sure you have utf-8 under the page <head> tag


Finally, if it still doesn't work, maybe the problem lies in your server. There is no encoding link configured in server.xml under tomcat. Find the location of Connector in server.xml and add URIEncoding="UTF-8" :


<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" URIEncoding="UTF-8"/>

If this is not added, the Chinese characters passed from the url are all garbled characters

Problem solved after joining.



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325631097&siteId=291194637