eclipse不乱码,页面也不乱码,数据添加到数据库是乱码

首先排除浏览器端和服务器端乱码问题,html页面编码要保证一致,浏览器如果有要提交的参数,该参数的编码方式将会与该页面一致。
get方式发送请求:
方法一:修改tomcat中的server.xml文件;
方法二:encodeURI是js的内置对象,xhr为ajax对象
var uri=’check_admin.do?adminCode=’+$(‘#abc’);
xhr.open(‘get’,encodeURI(uri),true);
post方式发送请求:
1.单单对于servlet来说:request.setCharacterEncoding(‘utf-8’);
2.对于spring框架,因为DisPatcherServlet是封装好的,无法对 DispatcherServlet去修改字符集,所以采用filter,在web.xml中配置

配置完还是没有解决?
查看数据库,数据库内容也是乱码
证明数据库有问题:在配置数据库时候应该在后面加上字符集编码方式


<property name="url" value="jdbc:mysql://localhost:3306/yourname?useUnicode=true&amp;characterEncoding=utf8"></property>  

如果是写在配置文件中,要这样写
url=jdbc:mysql://localhost:3306/yourname?useUnicode=true&characterEncoding=utf8

猜你喜欢

转载自blog.csdn.net/cycjq123/article/details/82631811