Accented letter and other languages like Mandarin and Arabic are tricky.
I guess you have not seen the last of this issue.
You should make sure that you keep your text encoded correctly in any link in the chain.
E.g.
- database ->java ->response->browser
- properties file ->jav-> response->browser
- request (param/form) ->response->browser
- java -> logger-> console
I suggest following this great answer
How to get UTF-8 working in Java webapps?
To adjust it to spring use spring’s CharacterEncodingFilter.
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>
org.springframework.web.filter.CharacterEncodingFilter
</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
If you are using i18n make sure to define the default Encoding for your ResourceBundleMessageSource e.g.
<bean id="messageSource"
class="org.springframework.context.support.ReloadableResourceBundleMessageSource"
>
<property name="basename" value="classpath:messages"/>
<property name="defaultEncoding" value="UTF-8"/>
<property name="useCodeAsDefaultMessage" value="false"/>
</bean>
Make sure your properties files are encoded correctly using Java’s native2ascii.
Or better if you use eclipse I recommend Property Editor plugin.
Sometime third-party framework break something and you need to do the “magical”
new String(yourstring, "UTF8")
For more information see here
Note that some view resolvers need to defined encoding as well.