【发布时间】:2010-04-18 09:52:36
【问题描述】:
在我的 jsf 页面上设置正确的字符集时遇到问题。我将 MySql db 与 latin2(ISO-8859-2 字符集)和 latin2_croatian_ci 排序规则一起使用。但是,我在设置支持托管 bean 属性的值时遇到了问题。
我页面顶部的页面指令是:
<%@ page language="java" pageEncoding="ISO-8859-2" contentType="text/html; charset=ISO-8859-2" %>
在我的头部包括:
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-2">
我的表单标签是:
<h:form id="entityDetails" acceptcharset="ISO-8859-2">
我已经在 web.xml 中创建并注册了 Filter,并使用了以下 doFilter 方法实现:
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
request.setCharacterEncoding("ISO-8859-2");
response.setCharacterEncoding("ISO-8859-2");
chain.doFilter(request, response);
}
但是,即当我通过 inputText 设置托管 bean 属性时,所有特殊(unicode)字符都替换为“?”字符。
我真的没有任何其他想法如何将字符集设置为页面以使其表现良好。有什么建议吗?
提前致谢。
【问题讨论】:
-
你是如何断定它们被破坏的?您是否在视图中查看过它们?还是在标准输出中? (你
System.out.print那些字符)。 -
抱歉我的回复延迟。我通过sql脚本将一些数据插入到db中,它们显示正确,所以我得出结论,显示正确的字符集没有问题。我在从 JSF 发送的支持 bean 集方法数据中记录(通过 slf4j 的标准输出和文件),并且数据已经损坏。此外,插入数据库的数据已损坏。
标签: jsf unicode character-encoding iso-8859-2