Results 1 to 6 of 6

Thread: UTF-8 character encoding problem with static content only

  1. #1

    Default UTF-8 character encoding problem with static content only

    Hi guys,

    once again, I have encountered some problems with handling character encoding while developing my webapp. I wish to use UTF-8 all over my website.
    What do I use?
    - IntelliJ
    - spring 2.5.x
    - freemarker
    - mysql
    - hibernate
    The problem appeared when I've changed hosting provider. At first, I have used a hosting company from USA. In order to make UTF-8 work, I had to convert my *.FTL files to UTF-8, which seemed reasonable.

    Recently I have changed my provider and static content in my *.FTL files is no longer rendered correctly in the browser. I figured out, that this is because of my change of the encoding in *.FTL. When I change its encoding back to ISO-8859-2, they appear as they should.

    My question is: can I avoid converting (FTL or JSP) files back and forth while changing the hosting provider? Is there any way I could avoid this?

    Few remarks:
    - I have specified UTF-8 encoding for Hibernate, Freemarker, webapp (web.xml), mysql (client & server)
    - Data fetched from MYSQL database are being displayed CORRECTLY, even though the rest of the freemarker template, in which they appear, IS NOT render correctly.

    Thanks in advance.

  2. #2
    Join Date
    Oct 2006
    Posts
    100

    Default

    You have to configure content type for for the freemaker layout view resolver bean.
    Code:
    <property name="contentType" value="text/html;charset=UTF-8"></property>
    I dont know if there are any specific freemarker arguments you have to specify, I use velocity and i had to specify velocity specific paramters.

    Try this, and see if that helps.

  3. #3

    Default

    Hi, gnandiga!

    I've already done that (prior to writing this post) but it didn't help:

    Code:
    <bean id="viewResolver" class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
        <property name="cache" value="true" />
        <property name="prefix" value="" />
        <property name="suffix" value=".ftl" />
        <property name="contentType" value="text/html;charset=UTF-8"/>
    </bean>
    As I've said earlier - everything works fine if I have UTF-8 file and I'm working with server from USA (I asume they use UTF too), but my other provider seems to use different encoding. I though I could force the servers to treat my files as UTF8 files, but I don't know if this is possible...

  4. #4
    Join Date
    Oct 2006
    Posts
    100

    Default

    The server is also needed to push the UTF-8, it is the encoding style of the response.

    We use tomcat and make that happen via URIEncoding property on the Connector.

  5. #5

    Default

    Well, the thing is I do not have the power to change anything with the server. I don't think my provider will change the server encoding especially for me. Well, I guess I can rewrite my files and save them with different encoding, but I was trying to find more flexible solution.

    Thx.

  6. #6
    Join Date
    Nov 2004
    Posts
    3

    Default Had same problem and this worked for me

    Reason is that your new provider probably is using a Windows server. Thous the default encoding is different because it is based on the operating system.

    Code:
    <bean id="freemarkerConfig" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
    		<property name="templateLoaderPath">
    			<value>/WEB-INF/view/ftl/</value>
    		</property>
      		<property name="freemarkerSettings">
    			<props>
    				<prop key="default_encoding">UTF-8</prop>
    			</props>
    		</property>
    	</bean>
    
    	<bean id="viewResolver" class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
    		<property name="cache">
    			<value>true</value>
    		</property>
    		<property name="prefix">
    			<value></value>
    		</property>
    		<property name="suffix">
    			<value>.ftl</value>
    		</property>
    		<property name="contentType">
    			<value>text/html;charset=UTF-8</value>
    		</property>
    	</bean>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •