900字范文,内容丰富有趣,生活中的好帮手!
900字范文 > ssh linux mysql 乱码_JAVA SSH中文及其乱码问题的解决 6大配置点 使用UTF-8编码

ssh linux mysql 乱码_JAVA SSH中文及其乱码问题的解决 6大配置点 使用UTF-8编码

时间:2019-10-19 05:18:33

相关推荐

ssh linux mysql 乱码_JAVA  SSH中文及其乱码问题的解决 6大配置点 使用UTF-8编码

JSP,mysql,tomcat下(基于struts2)中文及其乱码问题的解决 6大配置点 使用UTF-8编码

目前对遇到J2EE 开发中 中文及其乱码问题,参考网上资料做个总结, 主要是6大配置点:

1 struts2配置 2 数据库 3 页面 4 jdbc连接 5 tomcat 6.hibernate配置

以下解决方法不分顺序,大家按照自己的配置对比,同时也欢迎大家补充

1 struts2配置

struts2在配置struts.properties文件中加上struts.i18n.encoding=UTF-8或者在struts.xml里加上 有的朋友说加上struts.locale=zh_CN,但是我的struts.locale为en_GB没有问题.

2 数据库

2.1 mysql的表的编码方式,其DDL应该为: ENGINE=InnoDB DEFAULT CHARSET=utf8; 可以使用show create table tbname查看.

2.2 安装mysql数据库时就应该以utf8编码默认安装查看mysql数据库默认编码方式可以在其目录下my.ini文件中找到mysql和mysqld下default-character-set值为utf8或者在mysql数据库命令行下以"/s;"查看.

3 页面

每个页面上加上< %@pagepageEncoding="UTF-8" contentType="text/html; charset=UTF-8" %> 这样在jsp页面里,点右键,查看编码方式则为UTF-8.

4 jdbc连接

设置characterencoding为UTF-8 如jdbc.mysql.url=jdbc:mysql://localhost:3306/db?useUnicode=true&characterEncoding=UTF8

5 tomcat

为了保证get/post数据都采用相同的UTF8编码,我们在server.xml中进行了如下设置:

其中,当当使用IIS作为webserver转发servlet/jsp请求时IIS是通过AJP协议,把请求转发到Tomcat监听的8009端口,所以需要配置端口8009的URIEncoding为UTF-8.

msyql数据库安装时候需要默认编码方式或者使用MySQL Server Instance Config Wizard 配置,

在设置Configure the MySQL Server 5.0 server instance那里的时候选择Manual Selected Default Character Set / Collation 为 UTF8 而不是默认的 LATIN1 在MYSQL里查看得 mysql> /s;

-------------- E:/MySQL/MySQL Server 5.0/bin/mysql.exe Ver 14.12 Distrib 5.0.51a, for Win32 (ia32) Connection id:2 Current database: Current user:[emailprotected] SSL:Not in use Using delimiter: ; Server version:

5.0.51a-community-nt MySQL Community Edition (GPL) Protocol version: 10 Connection:localhost via TCP/IPServer characterset: utf8 Db characterset: utf8 Client characterset: utf8 Conn. characterset:

utf8TCP port: 3306 Uptime: 25 sec Threads: 1 Questions: 4 Slow queries: 0 Opens: 12 Flush tables: 1 Open tables: 6 Queries per second avg: 0.160

my.ini文件内容为

[mysql]default-character-set=utf8# SERVER SECTION # ---------------------------------------------------------------------- # # The following options will be read by the MySQL Server. Make sure that # you have installed

the server correctly (see above) so it reads this # file. # [mysqld] # The TCP/IP Port the MySQL Server will listen on port=3306 #Path to installation directory. All paths are usually resolved relative to this. basedir="E:/MySQL/MySQL Server 5.0/" #Path to

the database root datadir="E:/MySQL/MySQL Server 5.0/Data/" # The default character set that will be used when a new schema or table is # created and no character set is defineddefault-character-set=utf8...........

6. H ibernate 配置

在hibernate.cfg.xml配置文件中加入这些来完成的

true

UTF-8

作者:risingsun001 发表于-9-2 22:16:40 原文链接

阅读:0 评论:0 查看评论

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。