tomcat 配置-Dfile.encoding

本文介绍如何在Tomcat服务器上解决中文乱码问题。通过修改catalina.bat或catalina.sh文件中的JAVA_OPTS参数,设置-Dfile.encoding=UTF-8来确保文件编码统一为UTF-8。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

file.encoding跟操作系统默认字符集有关,Windows下默认的是gbk,但我们程序一般IO流中字符编码一般都设置的是utf-8,这样会导致中文乱码。因此需要修改file.encoding为utf-8.如果应用容器是tomcat,可参考如下修改方法。


注意:引号"的位置以及是否为英文半角引号".


windows


  修改catalina.bat


  tomcat7以下:


  set JAVA_OPTS=%JAVA_OPTS% %LOGGING_CONFIG%的后面加上 -Dfile.encoding="UTF-8"


  tomcat7:


  set "JAVA_OPTS=%JAVA_OPTS% %LOGGING_CONFIG% -Dfile.encoding=UTF-8"






Linux


  修改catalina.sh 


  JAVA_OPTS="-Dfile.encoding=UTF-8"

"D:\Program Files\Java\jdk-17.0.14+7\bin\java.exe" -Dmaven.multiModuleProjectDirectory=E:\Study-Java-Temp\SpringBoot-Temp\high-School-supervise-evaluate -Djansi.passthrough=true -Dmaven.home=C:\Users\yongming\.m2\wrapper\dists\apache-maven-3.9.9-bin\4nf9hui3q3djbarqar9g711ggc\apache-maven-3.9.9 -Dclassworlds.conf=C:\Users\yongming\.m2\wrapper\dists\apache-maven-3.9.9-bin\4nf9hui3q3djbarqar9g711ggc\apache-maven-3.9.9\bin\m2.conf "-Dmaven.ext.class.path=D:\Program Files\JetBrains\ideaIU-2024.1.4.win\plugins\maven\lib\maven-event-listener.jar" "-javaagent:D:\Program Files\JetBrains\ideaIU-2024.1.4.win\lib\idea_rt.jar=59549:D:\Program Files\JetBrains\ideaIU-2024.1.4.win\bin" -Dfile.encoding=UTF-8 -classpath C:\Users\yongming\.m2\wrapper\dists\apache-maven-3.9.9-bin\4nf9hui3q3djbarqar9g711ggc\apache-maven-3.9.9\boot\plexus-classworlds-2.8.0.jar;C:\Users\yongming\.m2\wrapper\dists\apache-maven-3.9.9-bin\4nf9hui3q3djbarqar9g711ggc\apache-maven-3.9.9\boot\plexus-classworlds.license org.codehaus.classworlds.Launcher -Didea.version=2024.1.4 --update-snapshots -s D:\Tools\apache-maven-3.8.8\conf\settings.xml org.mybatis.generator:mybatis-generator-maven-plugin:1.4.1:generate [INFO] Scanning for projects... [ERROR] [ERROR] Some problems were encountered while processing the POMs: [ERROR] 'build.plugins.plugin[org.mybatis.generator:mybatis-generator-maven-plugin].dependencies.dependency.version' for com.mysql:mysql-connector-j:jar is missing. @ line 74, column 33 @ [ERROR] The build could not read 1 project -> [Help 1] [ERROR] [ERROR] The project com.evaluate:high-School-supervise-evaluate:0.0.1-SNAPSHOT (E:\Study-Java-Temp\SpringBoot-Temp\high-School-supervise-evaluate\pom.xml) has 1 error [ERROR] 'build.plugins.plugin[org.mybatis.generator:mybatis-generator-maven-plugin].dependencies.dependency.version' for com.mysql:mysql-connector-j:jar is missing. @ line 74, column 33 [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ER
03-08
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值