1、Servlet中文乱码:

在doPost或doGet方法里,加上以下两行即可:

response.setContentType("text/html;charset=UTF-8");
request.setCharacterEncoding("UTF-8");

 

2、MySQL中文乱码:

Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/test? useUnicode=true&characterEncoding=UTF-8","root","");

test是数据库名字,后面中文编码是UTF-8

root是用户名,我的数据库没有密码,所有最后是空的(" ")

 posted on 2016-07-13 12:07  布鲁布鲁sky  阅读(355)  评论(0编辑  收藏  举报