一.说明:本文是解决三个问题:
1.从jsp页面跳转到Servlet时,使用String name=request.getParameter("name"),获取jsp页面中的中文,用System.out.println(name);方法输出时出现中文乱码。
解决方法:在Servlet的 doGet()和doPost()方法的最前面加上下面的三条语句。、
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=utf-8");
2.MysQL不能输入中文。
解决方法:新建数据库是选择 字符集为:gb2312 -- GB2312 Simplified Chinese (Navicat for MySQL)
3.MyEclipse能显示中文,MySQL也能显示中文,但是通过MyEclipse将中文数据插入到数据库,数据库中文乱码
解决方法:修改数据库链接语句,红线部分为要加入的内容
usrer(数据库名称)root(数据库管理员用户名)yin(管理员密码)
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/user?useUnicode=true&characterEncoding=gbk", "root", "yin");