Tomcat控制台乱码解决方法

本地使用Tomcat启动项目的时候,出现乱码,报错情况如下:


Connected to the target VM, address: '127.0.0.1:53135', transport: 'socket'
22-Jan-2019 14:10:19.099 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log Server version:        Apache Tomcat/8.5.37
22-Jan-2019 14:10:19.103 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log Server built:          Dec 12 2018 12:07:02 UTC
22-Jan-2019 14:10:19.103 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log Server number:         8.5.37.0
22-Jan-2019 14:10:19.103 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name:               Windows 10
22-Jan-2019 14:10:19.103 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version:            10.0
22-Jan-2019 14:10:19.103 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture:          amd64
22-Jan-2019 14:10:19.103 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home:             C:\Program Files\Java\jdk1.8.0_121\jre
22-Jan-2019 14:10:19.103 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version:           1.8.0_121-b13
22-Jan-2019 14:10:19.103 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor:            Oracle Corporation
22-Jan-2019 14:10:19.103 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE:         C:\Users\hong\.IntelliJIdea2018.2\system\tomcat\Tomcat_9_0_0_M17_dfac
22-Jan-2019 14:10:19.103 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME:         D:\Program Files\tomcat8.5.37
22-Jan-2019 14:10:19.104 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=C:\Users\hong\.IntelliJIdea2018.2\system\tomcat\Tomcat_9_0_0_M17_dfac\conf\logging.properties
22-Jan-2019 14:10:19.104 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
22-Jan-2019 14:10:19.104 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:53135,suspend=y,server=n
22-Jan-2019 14:10:19.104 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -javaagent:C:\Users\hong\.IntelliJIdea2018.2\system\captureAgent\debugger-agent.jar=file:/C:/Users/hong/AppData/Local/Temp/capture3095.props
22-Jan-2019 14:10:19.104 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote=
22-Jan-2019 14:10:19.104 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.port=1099
22-Jan-2019 14:10:19.104 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.ssl=false
22-Jan-2019 14:10:19.104 淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcom.sun.management.jmxremote.authenticate=false
...

一共做了三件事:

1. 修改Tomcat配置文件,增加UTF-8编码

更改 Tomcat conf文件夹下的 service.xml配置,增加 URIEncoding="UTF-8",具体如下:

<Connector port="8080" protocol="HTTP/1.1" ​ connectionTimeout="20000" ​ redirectPort="8443" URIEncoding="UTF-8"/>

发现启动情况仍无改变

2. 更改idea配置,设置编码为UTF-8

打开 Setting,搜索 File Encoding,修改配置如下图:

发现启动情况仍无改变

3. 修改tomcat的conf下的logging.properties中的参数

java.util.logging.ConsoleHandler.encoding = UTF-8

改为

java.util.logging.ConsoleHandler.encoding = GBK

ok了。

转自:https://www.jianshu.com/p/4a09e464f440


 上一篇
SpringMvc(ssm)加入拦截器后swagger不能访问问题 SpringMvc(ssm)加入拦截器后swagger不能访问问题
只需要加入下面的配置即可。 @Configuration public class MyWebAppConfig extends WebMvcConfigurationSupport { @Bean LoginInter
下一篇 
could not resolve placeholder ‘redis.host1’ in string value “${redis.host1}” could not resolve placeholder ‘redis.host1’ in string value “${redis.host1}”
原因:spring 的配置文件2处地方导入了配置文件 Spring容器仅允许最多定义一个PropertyPlaceholderConfigurer(或 <context:property-placeholder />),其余的
  目录