This might be an obvious question. But I haven’t encountered this scenario before.
In my Spring MVC application, I have the following configuration in web.xml.
<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>
The data transfer between the browser and the server occurs via JSON using Jackson Mapper.
The request – response headers as in Firebug is below:
Response headers
Content-Type application/json;charset=UTF-8
Server Apache
Transfer-Encoding chunked
Request Headers
Accept application/json, text/javascript, */*; q=0.01
Accept-Encoding gzip, deflate
Accept-Language en-us,en;q=0.5
Cache-Control no-cache
Connection keep-alive
Content-Length 0
Content-Type application/json; charset=utf-8
Does this mean that the request-response is properly encoded?
Is looking at the headers the only way of determining the encoding used?
UPDATE
If as Polve mentions below, the settings affect only the interpretation as UTF-8, then what should I do encode my response in Spring MVC?
The CharacterEncodingFilter only sets the encoding you want the other side to interpret the response (or request) as.
The request does not says that you want UTF-8 via Accept-Charset, so the client can send whatever he wants, and your filter says that you will interpret it as utf-8, even if the client specified another encoding (forceEncoding=true).
So no, it does not mean that your request is properly encoded, it says that you should interpret what is coming as utf-8.