简体   繁体   English

从Cp1252到UTF-8的Spring MVC编码请求

[英]Spring MVC encode request from Cp1252 to UTF-8

There is a post request to my controller with JSON encoded in Cp1252 . 我的控制器有一个用Cp1252编码的JSON的发布请求。 How can I encode the request body to UTF-8 ? 如何将请求正文编码为UTF-8 I use Jackson to get a POJO. 我使用Jackson来获取POJO。

try to add this filter to your web.xml: 尝试将此过滤器添加到您的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. 我有一个类似的问题,这解决了它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从UTF-8格式的pdf文件中读取并将其写入cp1252格式的写入器中 - Reading from UTF-8 formatted pdf file and writing it to a writer in cp1252 format CP1252转UTF-8编码后的特殊字符 - Special characters after converting from CP1252 to UTF-8 encoding 将文件从cp1252转换为utf -8 java - Convert file from Cp1252 to utf -8 java Java CP1252至UTF8 - Java CP1252 to UTF8 UTF8无骨vs Cp1252 - UTF8 Bomless vs Cp1252 如何可靠地猜测 MacRoman、CP1252、Latin1、UTF-8 和 ASCII 之间的编码 - How to reliably guess the encoding between MacRoman, CP1252, Latin1, UTF-8, and ASCII 即使字符串采用UTF-8,电子邮件主题仍以CP1252编码设置 - EMail subject get set in CP1252 encoding even though the string is in UTF-8 是什么让Ant在Eclipse中使用UTF-8而不是我的系统默认Cp1252执行&#39;javac&#39;? - What would make Ant execute 'javac' in Eclipse with UTF-8 instead of my system default Cp1252? 为什么我的简化DES实现在Cp1252编码下可以正常工作,而在UTF-8下却不能正常工作? - Why is my implementation of Simplified DES working fine under Cp1252 encoding but not under UTF-8? 有没有办法使用 java 查找文件编码类型(UTF-8 或 ANSI 或 Cp1252 或其他) - Is there a way to find file encoding type (UTF-8 or ANSI or Cp1252 or others) using java
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM