之前在寫SSH時遇到編碼問題,本來打算好好學一下的,老闆的原因就夭折了,後來那個項目編碼一堆亂,最近,公司來了個較牛B的,然後從他那學到了不少,這裏就統一用UTF-8。
數據庫
建表時
create database xxx character set utf8;
mysql> show variables like '%char%';
+--------------------------+-------------------------------------+------
| 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 | utf8 |...... -- 服務器字符集
| character_set_system | utf8 |......
| character_sets_dir | D:\MySQL Server 5.0\share\charsets\ |......
+--------------------------+-------------------------------------+------
二、查看 MySQL 數據表(table) 的字符集。
mysql>show full columns from tablename;
mysql>show create table tablename;
mysql>show table status from sqlstudy_db like '%countries%';
+-----------+--------+---------+------------+------+-----------------+------
| Name | Engine | Version | Row_format | Rows | Collation |......
+-----------+--------+---------+------------+------+-----------------+------
| countries | InnoDB | 10 | Compact | 11 | utf8_general_ci |......
+-----------+--------+---------+------------+------+-----------------+------
連接數據庫時
url後面加上
?useUnicode=true&characterEncoding=utf-8
struts2裏的配置也要改成utf-8的
頁面也改成utf-8的
pageEncoding="utf-8"
頁面屬性裏的也改成utf-8
應該就沒問題了