Thursday, May 14, 2015

Make a web app fully UTF-8 compliant

Very useful link that explains what to do to make a web app fully UTF-8 compliant:
http://stackoverflow.com/questions/138948/how-to-get-utf-8-working-in-java-webapps

Especially the use of a servlet filter, or the dedicated SpringCharacterEncodingFilter has been very useful to filter out the more cumbersome cases (browser that supposedly sends UTF-8 encoded data but still the business logic doesn't parse them that way).

 <filter> 
    <filter-name>encoding-filter</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>FALSE</param-value> 
    </init-param> 
 </filter> 
 <filter-mapping> 
    <filter-name>encoding-filter</filter-name> 
    <url-pattern>/*</url-pattern> 
 </filter-mapping>

Further information:
http://wiki.apache.org/tomcat/FAQ/CharacterEncoding

No comments: