Struts2+Spring+Hibernate连接mysql中文乱码解决
1.struts.xml中设置
<constant name="struts.il8n.encoding" value="UTF-8"></constant>
2.jsp页面设置
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
3.数据库连接url
jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8
或
jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=gbk
相关文档:
解决乱码最好的方法是在项目设计之初,统一所有的字符集,例如页面、request对象以及数据库等等。
一、 几种常见的乱码现象:
1、页面乱码
单纯的页面乱码是很好解决的,只要修改头部适合的字符集即可,如果页面中文显示乱码,你可以把字符集修改为:gb2312或gbk。
2、页面之间传递的参数是乱码 ......
一、mysql服务操作
1、net start mysql //启动mysql服务
2、net stop mysql //停止mysql服务
3、mysql -h主机地址 -u用户名 -p用户密码 //进入mysql数据库
4、quit //退出mysql操作
5、mysqladmin -u用户名 -p旧密码 password 新密码 //更改密码
6、grant select on 数据库.* to 用户名@登录主机 identifie ......
[root@sql21 ~]# mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3 to server version: 5.1.26-rc-log
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> show databases;
+--------------------+
| Database &nb ......
数据库目录是MySQL数据库服务器存放数据文件的地方,不仅包括有关表的文件,还包括数据文件和MySQL的服务器选项文件。不同的分发,数据库目录的缺省位置是不同的。
数据目录的位置
缺省的数据库位置
缺省数据库的位置编译在服务器中。
◆如果您是在一个源程序分发包中安装 MySQL,典型的缺省位置可能是 /usr/local/var ......