spring-mvc无法解码汉字 [英] spring-mvc can not decode chinese characters

查看:147
本文介绍了spring-mvc无法解码汉字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已阅读此 jsp网页编码问题和此使用Spring-MVC / Java保存中文字符

从我的项目开始以来,我在web.xml中有以下代码片段,它似乎注入正确:

I had the following code fragment in web.xml since the start of my project and it seems to injected correctly:

<!-- Reads request input using UTF-8 encoding -->
    <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>

http请求有这个头content-type:application / x-www-form-urlencoded ; charset = UTF-8set
,但日志行显示:
请求正文Bean:[UserBean @ 4a8da092 fristname ='??',lastname ='??']

And the http request has this header "content-type:application/x-www-form-urlencoded; charset=UTF-8" set but the log line shows this: Request Body Bean:[UserBean@4a8da092 fristname = '??', lastname = '??']

还有一些事情是我使用NetBeans,如果我把鼠标移到变量firstname和lastname,它们会正确显示。
不知道我需要什么,才能使它工作。任何帮助将不胜感激。

Also something wield is that I use NetBeans, if I mouse over to the variable firstname and lastname, they are shown correctly. Not sure what else do I need to get it working. Any help would be appreciated.

推荐答案

听起来一切都很好,但是你的记录器不能显示这些字符或者你正在使用的文本查看器这些日志无法解码字符。

Sounds like everything is fine but your logger is not capable of showing those characters or perhaps the text viewer you are using to see those logs can not decode the characters.

您可以通过在十六进制编辑器中打开日志文件并查找匹配的UTF-8值来排除文本查看器与您的输入(具有前导1或显示为负值的字节)

You can rule out the text viewer by opening up the log file in a hex editor and looking for UTF-8 values that match up with your input (bytes that have a leading 1 or show up as negative values)

这篇关于spring-mvc无法解码汉字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆