当前位置:Gxlcms > 数据库问题 > Servlet、MySQL中文乱码

Servlet、MySQL中文乱码

时间:2021-07-01 10:21:17 帮助过:3人阅读

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是用户名,我的数据库没有密码,所有最后是空的(" ")

Servlet、MySQL中文乱码

标签:

人气教程排行