Internationalization using resource bundle properties in JSP, non-Latin text becomes Mojibake
Properties files are as per specification read using ISO-8859-1.
... the input/output stream is encoded in ISO 8859-1 character encoding. Characters that cannot be directly represented in this encoding can be written using Unicode escapes as defined in section 3.3 of The Java™ Language Specification; only a single 'u' character is allowed in an escape sequence. The native2ascii tool can be used to convert property files to and from other character encodings.
So, any character which is not covered by the ISO-8859-1 range needs to be escaped in the Unicode escape sequences \uXXXX
. You can use the JDK-supplied native2ascii
tool to convert them. You can find it in JDK's /bin
folder.
Here's an example assuming that foo_utf8.properties
is the one which you saved using UTF-8 and that foo.properties
is the one which you'd like to use in your application:
native2ascii –encoding UTF-8 foo_utf8.properties foo.properties
In your particular case, the property in question would then be converted to:
login = \u041B\u043E\u0433\u0438\u043D
This can then be successfully read and displayed in a JSP page with the below minimum @page
configuration:
<%@ page pageEncoding="UTF-8" %>
(the remainder you had is irrelevant as those are the defaults already when above is set)
If you're using a Java-aware IDE such as Eclipse, then you can just use its builtin properties file editor which should automatically be associated with .properties
files in a Java-faceted project. If you use this editor instead of the plain text editor / source editor, then it'll automatically escape the characters which are not covered by the ISO-8859-1 range.
See also:
- Unicode - How to get the characters right?
- How to internationalize a Java web application?