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.