用特殊字符形成字符编码问题 [英] Form character encoding problems with special characters

查看:182
本文介绍了用特殊字符形成字符编码问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我设置了这样的内容类型:

 <%@ page language =javacontentType =text / html; charset = ISO-8859-1pageEncoding =ISO-8859-1%> 

当我发送像áéíóú这样的特殊字符时,它们可以正确保存在数据库中。我的表格字符集是utf-8。



我想像这样将iso-8859更改为utf-8来标准化我的应用程序并接受更多的特殊字符:

 <%@ page language =javacontentType =text / html; charset = UTF-8pageEncoding =UTF-8 %GT; 

但是当我将其更改为utf-8时,特殊字符áéíóú未正确保存在数据库中。当我尝试保存á时,它被保存为áÃÃÃÃÃÃÃ>>>>>>>>在服务器端我使用的是Spring MVC。我得到这样的文本字段值:

  String strField = ServletRequestUtils.getStringParameter(request,
field );


解决方案

当您的网页不是 ISO-8859-1 ,您需要声明一个 web.xml 中的CharacterEncodingFilter : p>

 < filter> 
< filter-name> charsetFilter< / 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> charsetFilter< / filter-name>
< url-pattern> / *< / url-pattern>
< / filter-mapping>


Hello I have a jsp with an html form.

I set the content type like this:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" %>

When I send special characters like á é í ó ú they are saved correctly in the database. My table charset is utf-8.

I want to change iso-8859 to utf-8 like this to standardize my application and accept more special characters:

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>

but when I change it to utf-8 the special characters á é í ó ú are not saved correctly in the databse. When I try to save á it is saved as á

In the server side I'm using Spring MVC. I'm getting the text field value like this:

String strField = ServletRequestUtils.getStringParameter(request,
                    "field");

解决方案

When your pages are not ISO-8859-1, you need to declare a CharacterEncodingFilter in web.xml:

<filter>
    <filter-name>charsetFilter</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>charsetFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

这篇关于用特殊字符形成字符编码问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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