如何使用org.springframework.web.filter.CharacterEncodingFilter来纠正字符编码? [英] how to use org.springframework.web.filter.CharacterEncodingFilter to correct character encoding?

查看:616
本文介绍了如何使用org.springframework.web.filter.CharacterEncodingFilter来纠正字符编码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一些帮助。

我把代码片段放在我的 web.xml p>

I placed the code snippet below in my 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>
</filter>

<filter-mapping>
    <filter-name>encodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

并在我的 server.xml

<Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443" URIEncoding="UTF-8"/>

我的jsp页面编码为 UTF-8 我的mysql表编码为 utf8_general_ci

My jsp pages are encoded as UTF-8 and my mysql table is encoded as utf8_general_ci.

我的问题是,每当我保存<$ c $

My problem is that whenever I save a ñ it becomes ?.

当我尝试手动保存<$ <$ p $> c $ c>ñ在mysql终端中正确保存。我怀疑问题在于我的服务器或我的程序。请帮助。

When I tried to manually save ñ in the mysql terminal its saving properly. I suspect the problem lies within my server or my program. Please help.

推荐答案

我在 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>

这篇关于如何使用org.springframework.web.filter.CharacterEncodingFilter来纠正字符编码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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