使用下面語句查看編碼:
String encoding = System.getProperty("file.encoding");
結果輸出:ANSI_X3.4-1968,從而導致中文亂碼
通過 locale 查看服務器系統編碼,需要修改:
1在tomcat啟動腳本里加入 -Dfile.encoding=UTF-8 選項
2修改配置文件,使得如下環境變量為這樣的值:
LANG="en_US.UTF-8"
LC_ALL="en_US.UTF-8"
可使用locale 命令測試。
最后重啟服務器,即可。
參考自:https://confluence.atlassian.com/confkb/filesystem-encoding-is-written-as-ansi_x3-4-1968-even-though-the-server-is-set-to-utf-8-658735809.html