解决 IDEA 中 Tomcat 控制台乱码问题
解决 IDEA 中 Tomcat 控制台乱码问题
2026年5月26更新:
所有地方均使用 UTF-8 编码即可解决,包括:
- IDEA 控制台编码设置:
File -> Settings -> Editor -> General -> Console中,Default Encoding修改为UTF-8 - Tomcat 的
conf/logging.properties也使用UTF-8(默认就是)。 - IDEA 启动参数(
Help -> Edit Custom VM Options...)和 Tomcat 中的启动参数(Tomcat 编辑面板中的VM Options)中追加-Dfile.encoding=UTF-8。 - 重要:日志的配置文件中修改为
UTF-8(比如log4j.properties)。
以下信息已过时 ↓
- 打开Tomcat安装目录:
apache-tomcat-9.0.14-windows-x64/conf/logging.properties 大概在50多行注释这一句#java.util.logging.ConsoleHandler.encoding = UTF-8(或者添加语句:java.util.logging.ConsoleHandler.encoding = GBK)- 是所有的
UTF-8改为GBK!
不要修改Tomcat在idea中的 VM options,也不要修改idea启动配置idea64.exe.vmoptions,不要在这两项后添加-Dfile.encoding=UTF-8
我估计是控制台代码页是GBK的才会乱码(在cmd输入chcp可以看到 活动代码页: 936这是简体中文的意思),Tomcat默认UTF-8的,或者有种根治的方法:在 控制面板 -> 时钟和区域 -> 区域 -> 管理 -> 更改系统区域设置 -> 使用Unicode-8提供全球语言支持,不过这样做可能会有一些软件乱码,下次重装系统的时候试试。