1.数据库--->页面:
jdbc.url jdbc:mysql://localhost:3306/数据库名?useUnicode=true&characterEncoding=utf-8
2.页面--->后台action
<filter>
<filter-name>encodingFilter</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>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
在web.xml文件中加入以上代码,注意加的位置
3.导入工程出现的乱码
(my)eclipse的工具栏上Window--Preferences--General--context Type右侧 Text -- Java Source File 最下面的default encoding改为UTF-8 更新即可4.以上解决不了,用如下方法试试
找到tomcat文件夹下的sevlet.xml文件的对应位置加入一下内容<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443"
URIEncoding="UTF-8"/>
5.HttpServletRequest getParameter取参时乱码
Stirng xxx = new String(request.getParemeter().getBytes("ISO-8859-1"),"UTF-8");