views:

1328

answers:

3

hey guys,

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

A: 

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

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

for some reason this thing isn't working at all for me :( .

any insight would be helpful

thanks

+2  A: 

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