我在我的Web应用程序(JSF 1.2,Spring和Tomcat 7)中遇到charset编码问题,而且我已经用尽了测试内容以查看它出错的地方.
每当我提交类似'çã'的内容时,我会得到'çã':这意味着我在UTF-8上发布的数据在JSF生命周期的某个地方被转换为ISO-8859-1.
我知道错误的转换是UTF-8到ISO-8859-1,因为它的输出相同:
System.out.println(new String("çã".getBytes("UTF-8"), "ISO-8859-1"));
Run Code Online (Sandbox Code Playgroud)
我相信错误的转换是在JSF生命周期中的某个地方(它可以在之前吗?)因为我在我的MB中设置了一个验证器:
public void debugValidator(FacesContext context, UIComponent component,
Object object) throws ValidationException {
System.out.println("debug validator:");
System.out.println(object);
System.out.println("\n");
throw new ValidationException("DEBUG: " + object.toString());
}
Run Code Online (Sandbox Code Playgroud)
并且它的消息返回:"DEBUG:çã"
<?xml version="1.0" encoding="UTF-8"?>.CharacterEncodingFilter在我的web.xml中将请求字符编码设置为UTF-8.URIEncoding="UTF-8"Tomcat的server.xml文件,只是为了保证你知道我还能测试什么吗?可能是我的错误假设?
提前致谢!