PrimeFaces 3.x中的UTF-8 [英] UTF-8 in PrimeFaces 3.x
问题描述
我有一个非常简单的应用程序,我的索引页中有一个inputtext和一个转到page2.xhtml的按钮.
I have a very simple application,there is an inputtext in my index page and a button to go to page2.xhtml.
<h:body>
<h:form>
<h:inputText value="#{mainBean.testValue}"/>
<p:commandButton update="myoutput" value="ajax call" ajax="false"/>
<p:separator />
<h:commandButton action="#{mainBean.gotoPageTwo}" value="goto Page2"/>
<br/>
<h:outputText value="#{mainBean.testValue}" id="myoutput"/>
</h:form>
</h:body>
</html>
我使用PrimeFaces 2.2.1测试了此应用程序,没有问题. 但提交上述每个按钮后,我的UTF-8字符将被销毁. 我测试了过滤器,但是它不起作用. 是PrimeFaces 3.x中的错误吗? 谁能解决这个问题?
I tested this application with PrimeFaces 2.2.1 and there was no problem. but after submit each of the above button, my UTF-8 characters will destroy. I tested filter but it don't work. Is it a bug in PrimeFaces 3.x? Can any body solve this problem?
推荐答案
在PrimeFaces论坛上找到的答案的web.xml
示例不完整. <filter-mapping>
丢失.没有它,过滤器甚至根本不会运行.相应地添加
The web.xml
example of the answer you found at PrimeFaces forum is incomplete. The <filter-mapping>
is missing. Without that, the filter won't even run at all. Add it accordingly
<filter-mapping>
<filter-name>Character Encoding Filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
当您已经使用Servlet 3.0(Tomcat 7,Glassfish 3等)时,另一种方法是仅使用
When you're already on Servlet 3.0 (Tomcat 7, Glassfish 3, etc), an alternative is to use just the @WebFilter
annotation on the class. Don't forget to remove the filter entry from web.xml
.
@WebFilter("/*")
有关PrimeFaces 2.x-3.x升级过程中此字符编码问题的原因的背景说明,另请参见
For a background explanation of the cause of this character encoding problem during PrimeFaces 2.x-3.x upgrade, see also Unicode input retrieved via PrimeFaces input components become corrupted
这篇关于PrimeFaces 3.x中的UTF-8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!