CentOs-Tomcat-Angular2-编码UTF-8 [英] CentOs - Tomcat - Angular2 - Encoding UTF-8
问题描述
我在CentOs服务器中的Tomcat中部署了一个SpringBoot Angular应用程序.
I have a SpringBoot Angular app deployed in a Tomcat which is in a CentOs server.
CentOs语言环境:
CentOs locale :
LANG=fr_FR.UTF-8
LC_CTYPE="fr_FR.UTF-8"
LC_NUMERIC="fr_FR.UTF-8"
LC_TIME="fr_FR.UTF-8"
LC_COLLATE="fr_FR.UTF-8"
LC_MONETARY="fr_FR.UTF-8"
LC_MESSAGES="fr_FR.UTF-8"
LC_PAPER="fr_FR.UTF-8"
LC_NAME="fr_FR.UTF-8"
LC_ADDRESS="fr_FR.UTF-8"
LC_TELEPHONE="fr_FR.UTF-8"
LC_MEASUREMENT="fr_FR.UTF-8"
LC_IDENTIFICATION="fr_FR.UTF-8"
LC_ALL=
在Tomcat的catalina.sh片段中,我具有以下配置:
In the Tomcat's catalina.sh sript, I have the following config :
CATALINA_OPTS="$CATALINA_OPTS -Dfile.encoding='UTF-8'"
在Angular应用的index.html中:
In the index.html of the Angular app :
<meta charset="utf-8">
在父项目的pom.xml中:
In the pom.xml of the parent project :
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
所有文件均以UTF-8编码
All files are encoded in UTF-8
所有这些字符都不能很好地显示:
With all that some characters are not well displayed :
é -> é
à -> è
° -> °
...
但是,数据库中的字符显示得很好(数据库以ANSI编码)
However, the characters from the database are well displayed (the database is encoded in ANSI)
有人知道我的错误在哪里吗?
Does anyone have an idea where is my mistake ?
推荐答案
问题已解决,将字符集与js和html mime类型一起添加到了tomcat的web.xml中:
Problem was resolved adding the charset to the js and html mime types into the tomcat's web.xml :
<mime-mapping>
<extension>html</extension>
<mime-type>text/html;charset=UTF-8</mime-type>
</mime-mapping>
<mime-mapping>
<extension>js</extension>
<mime-type>text/javascript;charset=utf-8</mime-type>
</mime-mapping>
这篇关于CentOs-Tomcat-Angular2-编码UTF-8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!