从Confluence db导出数据在控制台上乱码,在SPRING MVC页面也乱码,如”璟”。从confunce应用页面上看,无乱码。到底原因在哪里呢?
由于涉及的层非常多,只能用隔离法。
主要有几种可能
1)db里面的数据是否真有乱码
2)输出到页面上的汉字有乱码
3)页面编码识别有错
1.1.1用mysql控制台检查:
mysql> show variableslike'char%';
+--------------------------+-----------------------------------+
| Variable_name| Value|
+--------------------------+-----------------------------------+
| character_set_client| gb2312|
| character_set_connection | gb2312|
| character_set_database| utf8|
| character_set_filesystem | binary|
| character_set_results| gb2312|
| character_set_server| utf8|
| character_set_system| utf8|
| character_sets_dir| D:\MySQLServer5.0\share\charsets\ |
+--------------------------+-----------------------------------+
8 rows in set (0.05 sec)
mysql> show variableslike'coll%';
+----------------------+-------------------+
| Variable_name| Value|
+----------------------+-------------------+
| collation_connection | gb2312_chinese_ci |
| collation_database| utf8_general_ci|
| collation_server| utf8_general_ci|
+----------------------+-------------------+
3 rows in set (0.00 sec)
在控制台依然乱码。
下载MYSQL Administrator,用Mysql query browser查看,OK的。
只能剩下2种可能了。
1.1.2用JDBC直接连接DB
String url ="jdbc:mysql://127.0.0.1:3306/scmproj?user=root&password=mysql&useUnicode=true&characterEncoding=GB2312";
java.sql.Connection con = DriverManager.getConnection(url);
Statement stmt = con.createStatement();
String query = "select * from users where email='yi.suy@alibaba-inc.com'";
ResultSet rs = stmt.executeQuery(query);
while (rs.next())
{
// System.out.println(new
// String(rs.getString(1).getBytes("UTF8")).toString());
System.out.println(new String(rs.getString("fullname")));
}
同样输出正确。
1.1.3用IBATIS API连接DB
private static SqlMapClient sqlMapper;
private static SqlMapClient sqlMapper;Reader reader = Resources.getResourceAsReader("SqlMapConfig.xml");
// Reader reader =
// Resources.getResourceAsReader("D:/eclipse-SDK-3.3.2-win32/project/SCMProj/bin/SqlMapConfig.xml");
sqlMapper = SqlMapClientBuilder.buildSqlMapClient(reader);
reader.close();
List list =sqlMapper.queryForList("getProjectByName", queryStr);
SCMProject proj=(SCMProject) list.get(0);
正常。
剩下来的就是检查SPRING的编码格式了。
最后锁定SPRINGVelocityViewResolver: