CentOs - Tomcat - Angular2 - Encoding UTF-8

2019-05-31 04:42发布

问题:

I have a SpringBoot Angular app deployed in a Tomcat which is in a CentOs server.

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=

In the Tomcat's catalina.sh sript, I have the following config :

CATALINA_OPTS="$CATALINA_OPTS -Dfile.encoding='UTF-8'"

In the index.html of the Angular app :

<meta charset="utf-8">

In the pom.xml of the parent project :

<project.build.sourceEncoding>UTF-8</project.build.sourceEnc‌​oding>

All files are encoded in UTF-8

With all that some characters are not well displayed :

é -> é
à -> è
° -> °
...

However, the characters from the database are well displayed (the database is encoded in ANSI)

Does anyone have an idea where is my mistake ?

回答1:

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>