一般问题有几种:
1.mysql安装时没有设置编码:
-----解决方法:打开mysql安装目录:C:\Program Files\MySQL\MySQL Server 5.5 打开文件my.ini配置文件,找到 default-character-set=latin1 并改为: default-character-set=gbk,找到 character-set-server=latin1 并改为: character-set-server=gbk,修改完之后保存。 最后:我的电脑右击 “管理”进入之后选择“服务和应用程序”下的“服务” 找到“mysql”之后右击选择“重新启动”。 把jsp页面中的<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>改为<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>即可
2.在web。xml中增加拦截器:
-------<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>*.html</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
3.在数据库创建时,URL访问时后面一般加上:url=jdbc:mysql://localhost:3308/myoa?useUnicode=true&characterEncoding=UTF-8等
4.在jsp页面中设置:
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");