高了半天的乱码问题,搜这里搜那里的。
如果spring mvc 中文不想乱码,总结三点:
1.前端设定utf-8编码
<head> <meta charset="UTF-8"> </head>
2.tomcat 设定的utf-8编码
<Connector executor="tomcatThreadPool" port="8090" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" URIEncoding="utf-8"/>
3.工程后台在web.xml文件中设置过滤器filter
<filter> <filter-name>characterEncodingFilter</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>characterEncodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>