Roland Kofler
Roland Kofler

Reputation: 1332

Spring mvc static resources with utf-8 response header

How to enable the charset=utf-8 response header with static resources? The resource files are in UTF-8 but are displayed in ISO-Western-Europe encoding

EDIT: as asked by a comment here is the web.xml

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
  ...
  <filter>
   <filter-name>OCPsoft Rewrite Filter</filter-name>
   <filter-class>org.ocpsoft.rewrite.servlet.RewriteFilter</filter-class>
   <!-- <async-supported>true</async-supported> -->
  </filter>
  <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>
    <filter-name>HttpMethodFilter</filter-name>
    <filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
  </filter>
  <filter>
    <filter-name>springSecurityFilterChain</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
  </filter>
    <filter-mapping> 
    <filter-name>OCPsoft Rewrite Filter</filter-name> 
    <url-pattern>/*</url-pattern> 
    <dispatcher>FORWARD</dispatcher> 
    <dispatcher>REQUEST</dispatcher> 
    <dispatcher>INCLUDE</dispatcher> 
 </filter-mapping> 
  <filter-mapping>
    <filter-name>CharacterEncodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
  <filter-mapping>
    <filter-name>springSecurityFilterChain</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
  <filter-mapping>
    <filter-name>HttpMethodFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
  ...
</web-app>

Upvotes: 0

Views: 959

Answers (1)

Brian Clozel
Brian Clozel

Reputation: 59116

You can use the CharacterEncodingFilter (see javadoc).

Upvotes: 1

Related Questions