问题描述
在以下形式中,我们尝试将用户的输入返回到JSF的h:inputText
或PrimeFaces的p:inputText
.输入非拉丁字符(日语,希伯来语等)时,我们会遇到奇怪的行为:
In the following form, we try to return a user's input to JSF's h:inputText
or PrimeFaces' p:inputText
. We experience strange behavior when non-Latin characters (Japanese, Hebrew, etc. ) are entered:
在第一个请求上,我们得到了无法识别的字符集,但是在第二个请求上,我们得到了正确的结果.
On first request we get unrecognized character set, but on the second request - we get a correct result.
输入/输出示例(仅首次运行):
-
日语: 输入=日 输出=æ¥
Japanese: input = 日 output = æ¥
希伯来语: 输入=א 输出=×
Hebrew: input = א output = ×
JSF:
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.prime.com.tr/ui">
<body>
<h:form>
<h:outputLabel value="Name:"/>
<h:inputText value="#{newTestController.registeredCustomerFirstName}"/>
<h:commandButton value="Continue" action="#{newTestController.RegisteredNewCustomer(actionEvent)}"/>
</h:form>
</body>
</html>
后备豆:
@ManagedBean(name = "newTestController")
@SessionScoped
public class NewTestController {
private String registeredCustomerFirstName;
public String getRegisteredCustomerFirstName() {
return registeredCustomerFirstName;
}
public void setRegisteredCustomerFirstName(String registeredCustomerFirstName) {
this.registeredCustomerFirstName = registeredCustomerFirstName;
}
public void RegisteredNewCustomer(ActionEvent actionEvent) throws Exception {
}
}
推荐答案
如上所述-需要为应用程序服务器定义默认字符集.
As commented above - it is needed to define a default-charset for the application server.
对于玻璃鱼:将<parameter-encoding default-charset="UTF-8" />
添加到glassfish-web.xml
.
For glassfish: add <parameter-encoding default-charset="UTF-8" />
to glassfish-web.xml
.
对于其他应用程序服务器,请参阅BalusC的博客关于此问题.
For other application servers see BalusC's blog regarding this issue.
这篇关于首次提交时,JSF的h:inputText的字符集错误(仅)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!