Message body does not receive encoding even after adding filter

I have a 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 receive the Req Body encoding sent:

 { "hi": "æ‚šć„œ" } 

But received as

 { "hi": "??" } 
+5
source share
2 answers

Setting file.encoding is UTF8 in tomcat. I do not know why tomcat did not work 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 in many cases do not match those used in the java.io and java.lang APIs.

+1
source

CharacterEncodingFilter does not change the encoding of the content of the request (or response), it only sets the http-header of the request / response.

@ Check out the code for CharacterEncodingFilter.doFilterInternal (...)

+2
source

Source: https://habr.com/ru/post/1240792/


All Articles