一般项目里都是使用UTF-8格式,这里也都统一为UTF-8格式。
注意:因为windows系统中,其命令行窗口在解码字节数组时,默认使用本地字符集(对于我们就是GBK),所以修改之后在cmd窗口使用命令启动tomcat会出现中文乱码的情况。
-
修改idea配置编码格式:
Help->Edit Custom VM Options->在最后一行添加:-Dfile.encoding=UTF-8
Settings->Editor->File Encodeing->Global Encoding->选择UTF-8;Project Encoding->选择UTF-8;Default encoding for properties files->选择UTF-8 -
修改tomcat配置编码格式:
打开tomcat安装目录下的conf/server.xml文件,找到
添加 URIEcoding=“UTF-8” ,如下所示:
打开tomcat安装目录下的conf/logging.xml文件,将文件中配置java.util.logging.ConsoleHandler.encoding = GBK中的GBK修改为UTF-8