1

I'm trying to localize the things in JSP page using JSTL fmt tag where keys are defined in multiple properties files for all languages. It's working for all the lnguages except those which requires special characters like Japanese, Korean etc. It's showing a series of "????" for these languages. I even set the encoding to UTF-8. How is this caused and how can I solve it?

Sample key-value pairs in appMessage_ja.properties:

LABEL_PASSWORD = \u30d1\u30b9\u30ef\u30fc\u30c9
LABEL_LANGUAGE = \u8a00\u8a9e
Johan
  • 74,508
  • 24
  • 191
  • 319

1 Answers1

0

Question marks are usually only used when the char-byte mapper is all by itself aware of the encoding used in the both sides of the transfer. Any character in the source encoding which isn't supported by the target encoding will proactively be replaced by a question mark. In an average JSP/Servlet web application there are only 2 standard places where it can occur:

  1. Transferring characters between database and Java code through a JDBC connection.
  2. Transferring characters between webserver and webclient through HTTP response.

All other places would only end up in Mojibake (unintelligible sequence of characters, empty squares, replacement characters due to missing glyph in font, etc), not question marks.

In your case it's likely the second as there's no means of a database here. As you're using a JSP page, you should be setting the page encoding as below in top of the JSP page:

<%@page pageEncoding="UTF-8"%>

This basically sets the target encoding (and the charset attribute in HTTP response Content-Type header). Don't forget to also re-apply it on any include and tag file. If you'd like to configure it globally, so that you don't need to repeat the same boilerplate over all JSPs, then add the below entry to webapp's web.xml:

<jsp-config>
    <jsp-property-group>
        <url-pattern>*.jsp</url-pattern>
        <page-encoding>UTF-8</page-encoding>
    </jsp-property-group>
</jsp-config>

See also:

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555