spring-mvc can not decode chinese characters

断了今生、忘了曾经 提交于 2019-12-24 23:48:15

问题


I have read this jsp page encoding problem and this Save Chinese characters with Spring-MVC / Java

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>

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 = '??']

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.


回答1:


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.

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)



来源:https://stackoverflow.com/questions/5408340/spring-mvc-can-not-decode-chinese-characters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!