I have the CharacterEncodingFilter in place(first filter) in 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>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
But when I make a POST request, the body does not get encoded Req Body Sent:
{
"hi": "您好"
}
But received as
{
"hi": "??"
}
The CharacterEncodingFilter
does not change the encoding of the requests (or response) content, it set only the request/response http-header.
@See code of CharacterEncodingFilter.doFilterInternal(...)
Setting file.encoding
to UTF8
in tomcat worked. I don't know why tomcat was not working when system encoding was UTF-8
.
According to Java documentation here
The following tables show the encoding sets supported by Java SE 7. The canonical names used by the new java.nio APIs are in many cases not the same as those used in the java.io and java.lang APIs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With