UTF-8 Encoding

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

UTF-8 Encoding

melok393
Hello,

I'm new to Thymeleaf and got a problem with encoding. Environment is Thymeleaf 2.0, Spring 3, Tomcat 7.0.

web.xml
    <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>


servlet-context.xml
    <bean class="org.thymeleaf.spring3.view.ThymeleafViewResolver">
        ...
        <property name="characterEncoding" value="UTF-8" />
        ...
    </bean>


applicationContext.xml
    <bean id="templateResolver" class="org.thymeleaf.templateresolver.ServletContextTemplateResolver">
        ...
        <property name="characterEncoding" value="UTF-8" />
        ...
    </bean> 


Tomcat
URIEncoding is set as UTF-8.


messages.properties
Is encoded to UTF-8 and looks like:
home.login = Вход


Result
While I'm using th:text in a template (for ex: Login), result is displayed like this:
Вход


What do I miss?

Thanks to help :)
Reply | Threaded
Open this post in threaded view
|

Re: UTF-8 Encoding

Antibrumm
Hi

I believe the problem lies with how the properties file is loaded. Even if the file is utf-8 encoded java will by default load it with iso-8859-1.
Heres a blog explaining another approach in java 1.6. but spring still uses the 1.5 one as far as i know.

http://jdevelopment.nl/internationalization-jsf-utf8-encoded-properties-files/

The point is. At the moment you have to use native2ascii which converts your characters into unicode. This is also explained in the blog.


I would be happy to know if spring supports already the "new" way.