tomcat服务器上utf8编码的文件乱码解决方法
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.
tomcat服务器上utf8编码的文件乱码解决方法
对于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
出现这个问题,应该跟
SiteMesh
过滤器有关系,也和操作系统初始值有关系,在过滤器中没有取到字符集后选择了ISO8859-1
导致的。所以在操作系统中制定字符集就可以解决。
本文内容整理自:https://blog.csdn.net/winderain/article/details/51803440,感谢网友分享。
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK