4

I would like to add some characters with accents in my ".jsp" and ".html" but when I write those characters with accent in those files and load my pages:

  • "è" becomes "é"
  • "ç" becomes "ç"
  • "é" becomes "Ã "

Steps:

  1. I have configured Eclipse for creating all files with UTF-8 encoding (I have checked: all .jsp and .html files in the /src or /target folder are now UTF-8).

  2. None of my .jsp or .html files (inside /src or /target folder) explicitely contains those "é", "ç", "à ".

  3. All my .jsp contains those lines at the beginning :

    <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
    <!DOCTYPE html>
    <html lang="en">
        <head>
            <meta charset="utf-8" />
            <meta content="IE=edge" http-equiv="X-UA-Compatible" />
            <meta content="width=device-width, initial-scale=1" name="viewport" />
            <!-- ... -->
        </head>
    
  4. I have added those parameters in my appengine-web.xml:

    <system-properties>
        <property name="java.util.logging.config.file" value="WEB-INF/logging.properties"/>
        <!-- Added below -->
        <property name="file.encoding" value="UTF-8" />
        <property name="DEFAULT_ENCODING" value="UTF-8" />
    </system-properties>
    

I have also tried to add this thing showed in the GAE documentation but my application throws Exception :

<env-variables>
    <env-var name="DEFAULT_ENCODING" value="UTF-8" />
</env-variables>

GAE documentation says (source) :

To avoid conflicts with your local environment, the development server does not set environment variables based on this file, and requires that the local environment have these variables already set to matching values. (This does not apply to system properties.)

So I have removed this part and added the following environment variable in my system: DEFAULT_ENCODING = UTF-8

Further more:

  • When I use firebug to see the network, it shows Content-Type text/html; charset=utf-8 for my loaded page.
  • Google's tool has already added the <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> in my pom.xml when I've generated my project.

Interesting fact:

  • When I load html code from my text files with AJAX, there is no problem, "é" or "ç" characters are ok. I use the BalusC's code ( and you can notice that he uses response.setCharacterEncoding("UTF-8"); so I don't know where the problem comes from).
  • On the development environment (my localhost), if I replace <%@ page language="java" contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" %> by this <%@ page pageEncoding="UTF-8" %> characters with accents are ok, but only on my localhost, then when I upload my project to Google App Engine servers it's still not ok, firebug doesn't show Content-Type text/html; charset=utf-8 anymore, and W3C Markup Validation Service tells me :

    Internal encoding declaration utf-8 disagrees with the actual encoding of the document (windows-1252)

My configuration:

  • Maven 3.2
  • IDE: Eclipse Luna
  • OS: Windows 7
Community
  • 1
  • 1
gokan
  • 1,028
  • 1
  • 14
  • 30
  • I had this kind of issue with eclipse and what i had to do was to change the default encoding of my files / project / workspace from cp1209 or something like that to UTF-8. Take a look at your files with an editor other than eclipse (i.e. notepad++) and see what file encoding it detects for your files. notepad++ can convert your files as well. In the long run i'd definetly change the workspace encoding though. – konqi Dec 07 '15 at 08:53
  • Also i had (and have) encoding issues with data saved and loaded from the dev server datastore. If that is the case it is safe to assume that these issues will disappear in live environment. – konqi Dec 07 '15 at 08:55
  • Since the response from your server claims `charset=utf-8`, it appears the original files themselves have issues. As suggested by another user, you should check them in another editor or even a hex editor to determine if the encoding is being properly done. – Nick Dec 09 '15 at 00:57

1 Answers1

-1

I ran into the same issue. My solution was to add at the top of my .jsp files that generate html the following tag: <%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

alextk
  • 5,713
  • 21
  • 34