ssh linux mysql 乱码_JAVA ,SSH中文及其乱码问题的解决 6大配置点 使用UTF-8编码
JSP,mysql,tomcat下(基于struts2)中文及其亂碼問題的解決 6大配置點(diǎn) 使用UTF-8編碼
目前對(duì)遇到J2EE 開發(fā)中 中文及其亂碼問題,參考網(wǎng)上資料做個(gè)總結(jié), 主要是6大配置點(diǎn):
1 struts2配置 2 數(shù)據(jù)庫 3 頁面 4 jdbc連接 5 tomcat 6.hibernate配置
以下解決方法不分順序,大家按照自己的配置對(duì)比,同時(shí)也歡迎大家補(bǔ)充
1 struts2配置
struts2在配置struts.properties文件中加上struts.i18n.encoding=UTF-8?或者在struts.xml里加上 有的朋友說加上struts.locale=zh_CN,但是我的struts.locale為en_GB沒有問題.
2 數(shù)據(jù)庫
2.1 mysql的表的編碼方式,其DDL應(yīng)該為: ENGINE=InnoDB DEFAULT CHARSET=utf8; 可以使用show create table tbname查看.
2.2 安裝mysql數(shù)據(jù)庫時(shí)就應(yīng)該以u(píng)tf8編碼默認(rèn)安裝查看mysql數(shù)據(jù)庫默認(rèn)編碼方式可以在其目錄下my.ini文件中找到mysql和mysqld下default-character-set值為utf8或者在mysql數(shù)據(jù)庫命令行下以"/s;"查看.
3 頁面
每個(gè)頁面上加上< %@page?pageEncoding="UTF-8" contentType="text/html; charset=UTF-8" %> 這樣在jsp頁面里,點(diǎn)右鍵,查看編碼方式則為UTF-8.
4 jdbc連接
設(shè)置characterencoding為UTF-8 如jdbc.mysql.url=jdbc:mysql://localhost:3306/db?useUnicode=true&characterEncoding=UTF8
5 tomcat
為了保證get/post數(shù)據(jù)都采用相同的UTF8編碼,我們?cè)趕erver.xml中進(jìn)行了如下設(shè)置:
其中,當(dāng)當(dāng)使用IIS作為webserver轉(zhuǎn)發(fā)servlet/jsp請(qǐng)求時(shí)IIS是通過AJP協(xié)議,把請(qǐng)求轉(zhuǎn)發(fā)到Tomcat監(jiān)聽的8009端口,所以需要配置端口8009的URIEncoding為UTF-8.
msyql數(shù)據(jù)庫安裝時(shí)候需要默認(rèn)編碼方式或者使用MySQL Server Instance Config Wizard 配置,
在設(shè)置Configure the MySQL Server 5.0 server instance那里的時(shí)候選擇Manual Selected Default Character Set / Collation 為 UTF8 而不是默認(rèn)的 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:? ? ? ? ? [email?protected] SSL:? ? ? ? ? ? ? ? ? ? Not in use Using delimiter:? ? ? ? ; Server version:
5.0.51a-community-nt MySQL Community Edition (GPL) Protocol version:? ? ? 10 Connection:? ? ? ? ? ? localhost via TCP/IP?Server characterset:? ? utf8 Db? ? characterset:? ? utf8 Client characterset:? ? utf8 Conn.? characterset:
utf8?TCP 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文件內(nèi)容為
[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 defined?default-character-set=utf8?...........
6. H ibernate 配置
在hibernate.cfg.xml配置文件中加入這些來完成的
true
UTF-8
作者:risingsun001 發(fā)表于2013-9-2 22:16:40 原文鏈接
閱讀:0 評(píng)論:0 查看評(píng)論
總結(jié)
以上是生活随笔為你收集整理的ssh linux mysql 乱码_JAVA ,SSH中文及其乱码问题的解决 6大配置点 使用UTF-8编码的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: win10 mysql5.5无响应_Wi
- 下一篇: 编写程序python输入任意大的自然数、