Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

i18n : Umlaut not being displayed correctly in JSP

I have a JSP that is supposed to display some German text from some .properties files by using fmt:message, e.g.

The corresponding entry in the .properties file is: service.test.hware.test = Hardware prüfen (umlaut between r and f in 2nd word).

On internet explorer this displays as:

Hardware prüfen

the umlaut being corrupted. Any ideas as to what is going on here? Note that we are using Spring MVC.

like image 758
fred basset Avatar asked Dec 17 '22 21:12

fred basset


2 Answers

The ü is typical for an UTF-8 originated ü being incorrectly encoded as ISO-8859-1 instead of UTF-8. Here's a programmatic evidence:

System.out.println(new String("ü".getBytes("UTF-8"), "ISO-8859-1")); // ü

Since you mention that the very same character from the properties file works fine in some JSP's, but not in other JSP's, then it means that the browser is by those JSP's not correctly been instructed to use UTF-8 to display the characters returned by the server.

This instruction happens in the HTTP Content-Type header. Using any HTTP header debugging tool, you must be able to figure the returned header. One of the popular tools is Firebug.

alt text

Note the presence of charset=utf-8.

Usually, in JSP this is achieved by simply placing the following line in top of the JSP file:

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

See also:

  • Unicode - How to get the characters right?
like image 101
BalusC Avatar answered Dec 19 '22 10:12

BalusC


If you've defined your Spring messageSource via org.springframework.context.support.ResourceBundleMessageSource the properties are loaded with iso-8859-1 encoding, even if the properties file is utf-8 encoded (Java loads properties per default with iso-8859-1 encoding).

Consider to use org.springframework.context.support.ReloadableResourceBundleMessageSource. You can configure the default encoding with that MessageSource implementation. See the Javadoc for further information/features of that class.

Example:

<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
    <property name="basename" value="classpath:message"/>
    <property name="defaultEncoding" value="UTF-8" />
</bean>
like image 45
Andreas Netter Avatar answered Dec 19 '22 11:12

Andreas Netter