项目部署到Linux系统上,访问网站,找不到携带有中文路径的静态资源,此时需要修改Linux的配置。
一。Linux配置字符转换
A.查看系统支持的字符编码:
locale -a
B.centos下,需要修改的地方
文件一:/etc/profile,vim编辑进入
在最后面加上:
`export LC_ALL="zh_CN.gbk"
export LANG="zh_CN.gbk"
文件二:/etc/locale.conf 加上:
LANG=zh_CN.gbk
系统文件实时生效:
source /etc/profile
C.最后是修改Tomcat的server.xml文件
文件三:
tomcat下的conf目录文件夹下server.xml文件中添加
URIEconding="UTF-8"
useBodyEncodingForURI="true"
经过修改后重新启动tomcat,发现图片可以正常显示
但是修改后Linux下cmd命令英文会乱码
在linux环境中中文显示正常,而英文却显示乱码
用 echo $LANG
显示编码为 zh_CN.gbk
解决方法:
直接输入
export LC_ALL=POSIX
即可
if(downloadurl.contains("%")){
int endIndex = downloadurl.lastIndexOf(".");
int fristIndex = downloadurl.indexOf("%");
String substring = downloadurl.substring(fristIndex, endIndex);
//字符编码设置
String decode = URLDecoder.decode(substring, "UTF-8");
downloadurl = downloadurl.replace(substring, decode);
}
注意:
静态资源路径命名中不能存在 #,%,?,/,\