4

tomcat服务器上utf8编码的文件乱码解决方法

 2 years ago
source link: https://www.bmqy.net/2639.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

tomcat服务器上utf8编码的文件乱码解决方法

发布于 2022年2月23日| 更新于 2022年2月23日| 分类于 清学小记| 标签 tomcat乱码utf8-bomutf8乱码| 0

对于tomcat服务器上的utf8文件乱码的问题,找到以下解决方法,特此记之:

  • jsp文件不乱码;
  • 只有html等静态资源文件乱码;
  • html文件charset设置正确;
  • 需要转为utf-8-bom编码才可以正常访问;

具体设置如下,其他非tomcat应用服务器也应该是一样的原理:

Linux

可以通过设置export LANG=zh_CN.UTF-8设置环境变量

Windows:

  • 如果通过startup.bat启动,则需要在catalina.bat中设置set JAVA_OPTS=-Xms256m -Xmx2048m -Dfile.encoding=utf-8

  • 如果是通过windows服务启动tomcat,则需要执行tomcatw.exe进行配置,增加-Dfile.encoding=utf-8
    tomcatw.exe设置

出现这个问题,应该跟SiteMesh过滤器有关系,也和操作系统初始值有关系,在过滤器中没有取到字符集后选择了ISO8859-1导致的。所以在操作系统中制定字符集就可以解决。

本文内容整理自:https://blog.csdn.net/winderain/article/details/51803440,感谢网友分享。

发表评论 取消回复

您的电子邮箱地址不会被公开。 必填项已用*标注

评论

显示名称 *

电子邮箱地址 *

网站地址

通过邮件通知我后续评论

通过邮件通知我有新文章


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK