javaspringjspmavenutf8-decode

Regional Characters not getting Displayed on JSP page


I have formatted by Maven Webapp with Spring to have localization features for English and Bengali. I load the messages I need for the page from Property files respectively for English and Bengali. If I directly add the characters to the page, they get rendered correctly. Also if I add Bengali characters in unicode (Ex: স) they get displayed correctly. But since the property file cannot be read easily, I added the text in normal Bengali text (Ex: স) but now they don't get displayed correctly. They're shown as "à¦à¦¦à§à¦" etc.

In every JSP page I have the following.

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

In my web.xml, I have included

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

Also I have,

<jsp-config>
    <jsp-property-group>
        <url-pattern>*.jsp</url-pattern>
        <page-encoding>UTF-8</page-encoding>
    </jsp-property-group>
</jsp-config>

And in my spring-servlet.xml

<bean id="messageSourceLocale"
      class="org.springframework.context.support.ResourceBundleMessageSource">
    <property name="basename" value="messages.messages" />
    <property name="defaultEncoding" value="UTF-8" />
</bean>

What am I doing wrong? How to fix this? Thanks in advance.


Solution

  • I had the same problem with slightly different technologies (Stpring, Maven, Pug(former Jade)). Adding this line in my Controller worked for me:

    @RequestMapping(value="/", produces = "text/html;charset=UTF-8")
    

    Thanks to this post.

    Hope that will be helpful!