1.问题描述:
通过getJSON方法,讲中文传递到Server端时,中文为乱码
2.解决办法
通过查找资料,好多都说配置web.xml
<filter> <filter-name>SpringEncodingFilter</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> <init-param> <param-name>forceEncoding</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>SpringEncodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
但是这并没有解决问题,继续查找资料发现此配置是针对POST请求的,GET请求配置需要修改Tomcat的server.xml配置
<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443"/>
修改为
<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" useBodyEncodingForURI="true"/>
时间: 2024-10-07 15:20:26