頁面顯示正常,但數據庫中中文變為 ???。
JDBC 連接未指定字符集,驅動默認使用 ISO-8859-1 或平台默認編碼傳輸,與數據庫 GBK 編碼不匹配。
String url = "jdbc:mysql://localhost:3306/dbname?useUnicode=true&characterEncoding=gbk";
// 或 utf8 (需數據庫表也為 utf8)
String url = "jdbc:mysql://localhost:3306/dbname?useUnicode=true&characterEncoding=utf8";
CHARSET=gbk。useUnicode=true&characterEncoding=gbk。<%@ page contentType="text/html;charset=GBK" %>。server.xml URIEncoding="GBK" (GET 參數)。request.setCharacterEncoding("GBK") (POST 參數)。