2
votes

I have an index.html file:

<!doctype html>
<html lang="fr" class="no-js fontawesome-i2svg-active fontawesome-i2svg-complete">
<head>
  <meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />
  <title>Annuaire Téléphonique</title>
...

and i deploy it into a war, served by Tomcat 9.0.35. The problem is that in the browser, the accents are like this: "Annuaire Téléphonique"

I found that the content-type served by Tomcat is false:

Every piece of Tomcat configuration is configured for UTF-8. My Linux bash defines LANG=UTF-8, and Tomcat is started with -Dfile.encoding=UTF-8

I also found that when asking form index.html, tomcat does not specify encoding, which is perfect for me as index.html itself contains the Content-Type meta with UTF-8, the browser display correctly the accents

Questions are:

  • Why index.html served as welcome file (http://127.0.0.1:10000/) is served as ISO-8859-1 ?
  • How can it be served as UTF-8 ? (AddDefaultCharsetFilter UTF-8 doesn't help)

Thanks for your help

1
Are you sure the selected welcome file is index.html (e.g. modify the file)? Which browser are you using? Can you add the configuration of the AddDefaultCharsetFilter? - Piotr P. Karwasz
I modified index.html, it is the file served. I tried with Chrome/Linux and Bing/Windows. Same with curl/localhost. Here is the filter configuration: <filter> <filter-name>addDefaultCharsetFilter</filter-name> <filter-class>org.apache.catalina.filters.AddDefaultCharsetFilter </filter-class> <init-param> <param-name>encoding</param-name> <param-value>UTF-8</param-value> </init-param> </filter> - Shimbawa
Please, edit your question and add the filter configuration there. If you don't have a filter mapping, the filter is not used. - Piotr P. Karwasz

1 Answers

0
votes

I found a working solution as I'm exposing a Spring application, with the following properties

spring.http.encoding.charset=UTF-8 spring.http.encoding.force-response=true

This behaviour is still strange to me...