Tomcat 9中文乱码

Tomcat 9中文乱码

  1. 问题:通过IDEA启动tomcat,控制台输出出现中文乱码问题;
  2. 原因:在IDEA中启动Tomcat,控制台显示的其实就是启动Tomcat的日志信息,之所以乱码,是因为IDEA设置的默认代码页为936也就是GBK,而Tomcat的日志信息编码为UTF-8;两者编码不一样当然会出现乱码问题;
  3. 解决方法:(此处仅演示一个方法)
    进入Tomcat的安装目录,找到conf目录下的logging.properties文件;
    使用notepad++/Edit/记事本打开logging.properties文件;
    将java.util.logging.ConsoleHandler.encoding = UTF-8改为java.util.logging.ConsoleHandler.encoding = GBK;

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.maxDays = 90
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.maxDays = 90
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.maxDays = 90
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.maxDays = 90
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

此时启动IDEA问题就解决了//此方法只是解决控制台输出日志中文乱码问题

tomcat目录及作用小结

/bin :存放各种平台下用于启动和停止Tomcat的脚本文件
/conf:存放tomcat的各种配置文件
/lib:存放tomcat服务所需的各种jar包
/logs:存放tomcat的日志文件
/temp:tomcat运行时用于存放临时文件
/webapps:当发布web应用时,默认情况下会将Web应用的文件存放于此目录
/work: tomcat把由JSP生成的Selvlet放于此目录下

你可能感兴趣的:(工具类)