内容简介:不改的话,不影响使用,因为报错基本都是英文显示的。但是这几个中文字乱码的看着难受。乱码的根本原因:Windows系统的cmd是GBK编码的,所以IDEA的下方log输出的部分的编码也是GBK的,然而Tomcat 9.0 版本默认log输出是UTF-8编码的,采用了两种不同的编码方式就会导致乱码。
前言
不改的话,不影响使用,因为报错基本都是英文显示的。但是这几个中文字乱码的看着难受。
乱码的根本原因:
Windows系统的cmd是GBK编码的,所以IDEA的下方log输出的部分的编码也是GBK的,然而Tomcat 9.0 版本默认log输出是UTF-8编码的,采用了两种不同的编码方式就会导致乱码。
解决方案
修改Tomcat 日志输出为GBK编码
先打开tomcat的安装目录
编辑 conf 目录下的 logging.properties,把里面的UTF-8 通通改成 GBK,保存,重启Tomcat,即可生效。
# Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You under the Apache License, Version 2.0 # (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. handlers = 1catalina.org.apache.juli.FileHandler, 2localhost.org.apache.juli.FileHandler, 3manager.org.apache.juli.FileHandler, 4host-manager.org.apache.juli.FileHandler, java.util.logging.ConsoleHandler .handlers = 1catalina.org.apache.juli.FileHandler, java.util.logging.ConsoleHandler ############################################################ # Handler specific properties. # Describes specific configuration info for Handlers. ############################################################ 1catalina.org.apache.juli.FileHandler.level = FINE 1catalina.org.apache.juli.FileHandler.directory = ${catalina.base}/logs 1catalina.org.apache.juli.FileHandler.prefix = catalina. 1catalina.org.apache.juli.FileHandler.encoding = UTF-8 2localhost.org.apache.juli.FileHandler.level = FINE 2localhost.org.apache.juli.FileHandler.directory = ${catalina.base}/logs 2localhost.org.apache.juli.FileHandler.prefix = localhost. 2localhost.org.apache.juli.FileHandler.encoding = UTF-8 3manager.org.apache.juli.FileHandler.level = FINE 3manager.org.apache.juli.FileHandler.directory = ${catalina.base}/logs 3manager.org.apache.juli.FileHandler.prefix = manager. 3manager.org.apache.juli.FileHandler.encoding = UTF-8 4host-manager.org.apache.juli.FileHandler.level = FINE 4host-manager.org.apache.juli.FileHandler.directory = ${catalina.base}/logs 4host-manager.org.apache.juli.FileHandler.prefix = host-manager. 4host-manager.org.apache.juli.FileHandler.encoding = UTF-8 java.util.logging.ConsoleHandler.level = FINE java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter java.util.logging.ConsoleHandler.encoding = UTF-8 ############################################################ # Facility specific properties. # Provides extra control for each logger. ############################################################ org.apache.catalina.core.ContainerBase.[Catalina].[localhost].level = INFO org.apache.catalina.core.ContainerBase.[Catalina].[localhost].handlers = 2localhost.org.apache.juli.FileHandler org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager].level = INFO org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager].handlers = 3manager.org.apache.juli.FileHandler org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/host-manager].level = INFO org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/host-manager].handlers = 4host-manager.org.apache.juli.FileHandler # For example, set the org.apache.catalina.util.LifecycleBase logger to log # each component that extends LifecycleBase changing state: #org.apache.catalina.util.LifecycleBase.level = FINE # To see debug messages in TldLocationsCache, uncomment the following line: #org.apache.jasper.compiler.TldLocationsCache.level = FINE java.util.logging.ConsoleHandler.encoding = UTF-8
修改IDEA为UTF-8编码
idea.exe.vmoptions、idea64.exe.vmoptions
修改idea.exe.vmoptions和idea64.exe.vmoptions这两个文件
分别在这两个文件的最后,添加一行 -Dfile.encoding=UTF-8
-Xms128m -Xmx750m -XX:ReservedCodeCacheSize=240m -XX:+UseConcMarkSweepGC -XX:SoftRefLRUPolicyMSPerMB=50 -ea -Dsun.io.useCanonCaches=false -Djava.net.preferIPv4Stack=true -Djdk.http.auth.tunneling.disabledSchemes="" -XX:+HeapDumpOnOutOfMemoryError -XX:-OmitStackTraceInFastThrow -Dfile.encoding=UTF-8
这个参数的作用是强制系统文件使用UTF-8编码,改完之后保存,重启IDEA即可。
最后更新于 2019-06-03 13:51:41 并被添加「tomcat」标签,已有 1 位童鞋阅读过。
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
猜你喜欢:- tomcat,jboss,weblogic乱码问题以及Java中各种乱码问题大汇总
- Perl中文乱码问题
- Perl中文乱码问题
- zabbix中文乱码解决方法
- pycharm中文乱码问题 总结
- Matplotlib中文乱码解决方案
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
RGB转16进制工具
RGB HEX 互转工具
XML 在线格式化
在线 XML 格式化压缩工具