My mistakes

Java Spring and UTF-8 encoding

Posted on: May 8, 2012

Things to take care

1) Set the contentType on the jsp via

<%@ page contentType="text/html;charset=UTF-8" %>

2) Set this tag inside the jsp:
<META HTTP-EQUIV="content-type" CONTENT="text/html; charset=UTF-8" />

3) Add the below filter to the web.xml

<!– Ensure UTF-8 encoded pages so that certain characters are displayed and submitted correctly –>
<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>

<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

4) Make sure the database fields have appropriate collation like utf-8, utf-16

Advertisements
Tags:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: