1

对我的控制器有一个 post 请求,其中 JSON 编码为Cp1252. 如何将请求正文编码为UTF-8?我使用杰克逊来获得 POJO。

4

1 回答 1

1

try to add this filter to your 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>

i had a similar problem and this solved it.

于 2013-08-16T08:53:53.523 回答