mysql中jsp中文乱码怎么解决[mysql入门教程]
JSP页面传输到MySQL数据库时,中文为乱码(数据库中存储乱码)解决方法:
将所有的涉及到编码的都设置为utf-8即可。
执行mysql> show variables like 'character%';命令查看mysql使用的编码方式:
mysql> show variables like 'character%';+--------------------------+------------------------------------------------------+
| Variable_name | Value |
+--------------------------+------------------------------------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | D:Program Filesmysql-5.6.20-winx64sharecharsets |
+--------------------------+------------------------------------------------------+
修改数据库编码执行命令: mysql> alter database db_name character set utf8;
修改其他编码: mysql> set names 'utf8';
设置JSP页面编码:在页面顶部添加:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
修改数据库连接DriverManager.getConnection(url, usr, pwd)的url:
String url = "jdbc:mysql://localhost:3306/db_name?useUnicode=true&characterEncoding=utf-8";
在发送页面和接收页面顶部都添加以下代码:
<% request.setCharacterEncoding("UTF-8");response.setCharacterEncoding("UTF-8");
response.setContentType("text/html; charset=utf-8");
%>
推荐:MySQL教程
以上是 mysql中jsp中文乱码怎么解决[mysql入门教程] 的全部内容, 来源链接: utcz.com/z/527258.html