Maciej Rumianowski's Weblog 

UTF-8 URL Encoding - Spring MVC on JBoss

by Maciej Rumianowski


Posted on Sunday Oct 06, 2013 at 07:33PM in General


For UTF-8 encoding of URLs and HTTP Requests there are 2 places that need setup. First is web.xml in which encoding Filter is added:

        <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>

Second is JBoss server settings, where system properties need to be added:

 <system-properties>
        <property name="org.apache.catalina.connector.URI_ENCODING" value="UTF-8"/>
        <property name="org.apache.catalina.connector.USE_BODY_ENCODING_FOR_QUERY_STRING" value="true"/>
    </system-properties>

Additionally if someone is using MySQL as a database data sources should be also set properly. Construct connection url as is shown below (& should be escaped &amp;):

<connection-url>jdbc:mysql://localhost:3306/mydatabase?useUnicode=true&amp;characterEncoding=UTF-8</connection-url>



No one has commented yet.

Leave a Comment

HTML Syntax: NOT allowed