Announcement Announcement Module
Collapse
No announcement yet.
Issues with UTF-8 encoding Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Issues with UTF-8 encoding

    Hi!

    I'm nearing my wits ends trying to get UTF-8 encoding to work with Spring MVC. I'm using maven with jetty plugin and running the application using "mvn jetty:run".

    A simple controller method returns UTF-8 characters, implementation as follows:
    Code:
    	@RequestMapping("/test")
    	@ResponseBody public String test() {
    		return "UTF8 content: \u010d\u0161\u017e - č";
    	}
    I've also included CharacterEncodingFilter (though I'm not sure that is really necessary) in web.xml:
    Code:
        <filter>
            <filter-name>CharacterEncodingFilter</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>CharacterEncodingFilter</filter-name>
            <url-pattern>/*</url-pattern>
        </filter-mapping>
    And the browser content looks like: UTF8 content: ???����

    Even though, the response headers seem to be right:
    Code:
    Content-Length:21
    Content-Type:text/html; charset=utf-8
    Server:Jetty(6.1.16)
    At first, I though the problem might be with velocity templates I'm using, so I coded a simple method to return the UTF-8 characters. I've also included encoding configuration in the POM file:
    Code:
      <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
      </properties>
    So what is going on? I could really use some help with this.

    Thanks!
Working...
X