今天在IDEA上启动tomcat的时候发现控制台会有乱码问题,例如这样:
06-Mar-2019 09:36:43.904 淇℃伅 [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["ajp-nio-8009"]
06-Mar-2019 09:36:43.908 淇℃伅 [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
06-Mar-2019 09:36:43.909 淇℃伅 [main] org.apache.catalina.startup.Catalina.load Initialization processed in 621 ms
06-Mar-2019 09:36:43.974 淇℃伅 [main] org.apache.catalina.core.StandardService.startInternal Starting service [Catalina]
06-Mar-2019 09:36:43.974 淇℃伅 [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/8.5.38
06-Mar-2019 09:36:43.990 淇℃伅 [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
06-Mar-2019 09:36:44.014 淇℃伅 [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-nio-8009"]
06-Mar-2019 09:36:44.019 淇℃伅 [main] org.apache.catalina.startup.Catalina.start Server startup in 109 ms
Connected to server
对于我这种强迫症果断忍不了呀 于是 去百度去寻找一下解决方案,发现网上流传的方法 大部分都是分为这几步:
设置idea编辑器的编码:File->Settings->File Encodings
然后配置tomcat的编码问题:
Run/DeBug Configurations
在VM options填写-Dfile.encoding=UTF-8:
再不然就是
打开idea安装目录-bin
打开idea.exe.vmoptions和idea64.exe.vmoptions文件
在文件后面添加一行:-Dfile.encoding=UTF-8
可是,根据这一套下来 发现自己的问题还是没解决,最后又苦苦寻找,寻找到了一种方法,才得以解决,特来分享,如果前几种方法满足不了你,就试试吧。
到tomcat/conf/目录下
修改logging.properties 找到 java.util.logging.ConsoleHandler.encoding = utf-8这行 更改为 java.util.logging.ConsoleHandler.encoding = GBK
修改以后 ,再运行:
06-Mar-2019 09:55:55.621 信息 [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
06-Mar-2019 09:55:55.651 信息 [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["ajp-nio-8009"]
06-Mar-2019 09:55:55.658 信息 [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
06-Mar-2019 09:55:55.659 信息 [main] org.apache.catalina.startup.Catalina.load Initialization processed in 651 ms
06-Mar-2019 09:55:55.719 信息 [main] org.apache.catalina.core.StandardService.startInternal Starting service [Catalina]
06-Mar-2019 09:55:55.719 信息 [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/8.5.38
06-Mar-2019 09:55:55.739 信息 [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
06-Mar-2019 09:55:55.757 信息 [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-nio-8009"]
06-Mar-2019 09:55:55.763 信息 [main] org.apache.catalina.startup.Catalina.start Server startup in 103 ms
Connected to server
好了 成功了 分享给大家