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.
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.
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" %>
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With