tomcat解决控制台打印中文乱码问题
tomcat解决中文乱码问题
最近回去玩tomcat,发现控制台打印老输出中文乱码
网上看了好多tomcat解决中文乱码的帖子,但是都没能解决我的问题,然后自己研究了一下,总结一下经验
因为和后端交互 涉及到的编码就比较复杂一点。
首先是tomca下conf的 web.xml文件,插入
<init-param>
<param-name>fileEncoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
这个是和你项目用的编码统一。
然后就是conf下的logging.properties配置,设置GBK和UTF-8都可以。
1catalina.org.apache.juli.AsyncFileHandler.level = FINE
1catalina.org.apache.juli.AsyncFileHandler.directory = ${catalina.base}/logs
1catalina.org.apache.juli.AsyncFileHandler.prefix = catalina.
#1catalina.org.apache.juli.AsyncFileHandler.encoding = GBK
1catalina.org.apache.juli.AsyncFileHandler.encoding = UTF-8
2localhost.org.apache.juli.AsyncFileHandler.level = FINE
2localhost.org.apache.juli.AsyncFileHandler.directory = ${catalina.base}/logs
2localhost.org.apache.juli.AsyncFileHandler.prefix = localhost.
#2localhost.org.apache.juli.AsyncFileHandler.encoding = GBK
2localhost.org.apache.juli.AsyncFileHandler.encoding = UTF-8
3manager.org.apache.juli.AsyncFileHandler.level = FINE
3manager.org.apache.juli.AsyncFileHandler.directory = ${catalina.base}/logs
3manager.org.apache.juli.AsyncFileHandler.prefix = manager.
#3manager.org.apache.juli.AsyncFileHandler.encoding = GBK
3manager.org.apache.juli.AsyncFileHandler.encoding = UTF-8
4host-manager.org.apache.juli.AsyncFileHandler.level = FINE
4host-manager.org.apache.juli.AsyncFileHandler.directory = ${catalina.base}/logs
4host-manager.org.apache.juli.AsyncFileHandler.prefix = host-manager.
#4host-manager.org.apache.juli.AsyncFileHandler.encoding = GBK
4host-manager.org.apache.juli.AsyncFileHandler.encoding = UTF-8
java.util.logging.ConsoleHandler.level = FINE
java.util.logging.ConsoleHandler.formatter = org.apache.juli.OneLineFormatter
#java.util.logging.ConsoleHandler.encoding = GBK
java.util.logging.ConsoleHandler.encoding = UTF-8
但是设置完之后,tomcat里VM options的参数要和log.properties设置一样的编码,控制台打印就不是中文乱码了。
至于为啥我也不知道,记录一下,也可以帮助一些还没解决问题的小伙伴、