0

I am trying to display some nepali langauage charcaters in my spring MVC webapp with freemarker,

i did everything like i have character encoding filter in my 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>

My freemarker configuration is like

<bean id="viewResolver" class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
        <property name="cache" value="true"/>
        <property name="prefix" value=""/>
        <property name="contentType" value="text/html; charset=UTF-8"/>
        <property name="suffix" value=".ftl"/>
        <property name="exposeSpringMacroHelpers" value="true"/>
</bean> 

and in template i have

<meta http-equiv="content-type" content="text/html; charset=UTF-8">

defined i just see some weird charcaters in my page. Thought the response header has the correct content type "text/html; charset=UTF-8"

Not sure what and where's the problem. I even tried to set the content type from the controller response.setContentType('text/html; charset=UTF-8");

Help guys

6
  • where is your content from? is your datasource in a format or type that supports extended character sets? Commented May 27, 2009 at 18:49
  • actually i am trying to read from messages.properties file using <@spring.message code='error-input'/> tag Commented May 27, 2009 at 18:50
  • Are you positive that the messages.properties file is itself UTF-8 encoded? There is a good chance (if you're on Windows), that it's actually ISO 8859-1. Could you give an example of a character you expect to see as well as what you are actually seeing? Commented May 27, 2009 at 18:53
  • i am on a mac i have a propety like Jestha.nepali=बैशाख in messages.properties but i am getting बà¥à¤¶à¤¾à¤ in my page. Commented May 27, 2009 at 18:55
  • my properties file is UTF-8 encoded. Commented May 27, 2009 at 19:00

2 Answers 2

4

ok i fixed this issue, i used ReloadableResourceBundleMessageSource instead of ResourceBundleMessageSource with property defaultEncoding to UTF-8 so also had to add classpath for basename property value.

<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basename" value="classpath:messages"/>
<property name="defaultEncoding" value="UTF-8"/>
<property name="useCodeAsDefaultMessage" value="false"/>
</bean>

it works now..

Sign up to request clarification or add additional context in comments.

Comments

0

Are you sure the content is correct? Perhaps it's not valid UTF-8.

Are the "weird" characters only at the very beginning? Then they could be Windows formatted UTF-8 BOM (byte order marking).

1 Comment

i am on mac but looks like it's something to do with my eclipse file and content type association .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.