標籤:prot ogr csdn client out dir eclipse 介面 protocol
前言:項目想要避免亂碼情況的出現,要保持伺服器、資料庫、項目、以及前端編碼一致。
一、項目以及前端編碼,設定。
myeclipse--->右鍵項目--->Properties--->Resource--->Text file encoding----->選擇utf-8---->apply--->ok
二、tomcat6.x伺服器編碼設定
D:\apache-tomcat-6.0.37\conf\server.xml,
[html] view plain copy
- <Connector port="8080" protocol="HTTP/1.1"
- connectionTimeout="20000"
- redirectPort="8443" URIEncoding="UTF-8"/>
[html] view plain copy
- <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" URIEncoding="UTF-8"/>
後面的URIEncoding="UTF-8"就是所添加進去的內容
三、資料庫MySQL5.5設定;
①先開啟 運行--->cmd--->net stop MySQL 關閉mysql的服務
②C:\Program Files (x86)\MySQL\MySQL Server 5.5\my.ini
修改如下四個欄位為
[html] view plain copy
- [client]
- port = 3306
- default-character-set=utf8
[html] view plain copy
- [mysql]
- default-character-set=utf8
[html] view plain copy
- [mysqld]
-
- character-set-server=utf8
- port = 3306
[html] view plain copy
- character-set-server=utf8
儲存。
③開啟 運行--->cmd--->net start mysql 開啟MySQL的服務
④開啟MySQL的命令列介面,輸入密碼進入後
執行 show variables like ‘character%‘;該語句,顯示如下即表示設定成功
Java web後台插入資料庫中文亂碼問題解決