I have a Spring MVC J2EE application that leverages Spring's localeChangeInterceptor
and CookieLocaleResolver
to render locale-driven support. This is working, however when I try to encode letters with accent marks, the front-end fails to render them as expected.
Here's a snippet from my webmvc-config.xml file:
<!-- Internalization and localization support -->
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basename" value="classpath:messages" />
<property name="defaultEncoding" value="UTF-8"/>
</bean>
<bean id="localeChangeInterceptor" class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
<property name="paramName" value="lang" />
</bean>
<bean id="localeResolver"
class="org.springframework.web.servlet.i18n.CookieLocaleResolver">
<property name="defaultLocale" value="en"/>
</bean>
<bean id="handlerMapping" class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
<property name="interceptors">
<ref bean="localeChangeInterceptor" />
</property>
</bean>
Along with this I have some message_xx.properties files that contian my tags to render things out. Included are tags like this with accent marks embedded: district.manager.approval=Aprobación del Gerente de Distrito
. My beef is that this displays exactly like this on the front-end instead of showing me Aprobación del Gerente de Distrito
.
Any idea where I could have gone wrong?
After poking around a bit, it seems I left out a key detail: this only seems to be happening when I use JSTL
<c:set>
along with my Spring tags where the encoding does not work properly. As it turns out, when using<c:out>
, you need to accompany it with theescapeXml="false"
attribute. Here is what I did and it seems to be working appropriately now:This is set in one page
This is consumed in an imported page
And it handsomely gives me this:
REVISIÓN Y APROBACIÓN DEL GERENTE DE DISTRITO
Thanks everyone for your responses!