【发布时间】:2014-05-07 21:32:29
【问题描述】:
你好,
我在 NetBeans 7.4 中开发了一个 JSF2.2 Web 应用程序。它在 Apache Tomcat 7.0.50 上运行良好。但是现在我切换到 GlassFish 4 并且遇到了一些塞尔维亚语字符的问题(Ć、Č、Š、Đ、Ž...)
MySQL 数据库具有 utf8_general_ci 排序规则,以及所有表和每个 varchar 列。
连接网址:
jdbc:mysql://localhost:3306/sportal?useUnicode=true&characterEncoding=UTF-8&characterSetResults=UTF-8
web.xml 有以下部分:
<context-param>
<param-name>PARAMETER_ENCODING</param-name>
<param-value>UTF-8</param-value>
</context-param>
supporters.xhtml 文件,用于显示表格内容:
<h:dataTable id="listSupportersTable" value="#{supportersBean.list}"...>
...
<h:outputText value="#{row.name}"/>
...
</h:dataTable>
在 SupportersBean.java 中,我生成一个列表并出于调试目的打印结果:
...
while (resultSet.next()) {
supporter.setName(resultSet.getString("name"));
System.out.println(resultSet.getString("name") + ", " + supporter.getName());
list.add(supporter)
}
...
出于测试目的,我在表中做了一项,name=Ć(它在 MySQL 中正确显示)。在 supporters.xhtml 页面上,名称也是 Ć,但 println 给出:Ć, Ć
为了编辑条目,我在 supporters.xhtml 页面上创建了一个 commandLink,操作如下:
action="#{supportersBean.editSelected(event)}"
...我给了它一个参数:
<f:param name="supportersName" value="#{row.name}"/>
这是 editSelected 过程:
public String editSelected(AjaxBehaviorEvent event) {
newName=FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("supportersName");
System.out.println("newName="+newName); // for debugging
isEditing = true;
return "editSupporters.xhtml?faces-redirect=true";
}
println 给我:newName=Ć
editSupporters.xhtml 部分:
<h:inputText value="#{supportersBean.newName}"/>
在此字段中,我看到了字符 Ä。我这里什么都没做,我只点击保存按钮,它执行以下操作:
supporter.setName(newName);
System.out.println("Updated: "+newName);
dao.update(supporter);
println 给出:更新:Ć
在此之后,我的 supporters.xhtml 页面上的 outputField 的值为 ÃÂ。如果我再次单击 Edit,inputText 字段的值将是:ÃÂÃÂ,当我单击 Save 时,outputField 将是 ÃÂÃÂÃÂÂ...
最后,在这两个编辑/保存之后,我通过 phpMyAdmin 检查我的表。列中的值为:×
有谁知道问题出在哪里???
【问题讨论】:
标签: java mysql jsf utf-8 glassfish