无法从上下文将请求字符编码设置为UTF-8 [英] Unable to set request character encoding to UTF-8 from context
问题描述
我正在尝试将Primefaces中的示例实现为WAB包。
I'm trying to implement example from Primefaces into WAB package.
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui" >
<h:head>
<ui:insert name="header">
<ui:include src="header.xhtml"/>
</ui:insert>
</h:head>
<h:body>
<h1><img src="resources/css/images/icon.png" alt="NVIDIA.com" /> History Center</h1>
<!-- layer for black background of the buttons -->
<div id="toolbar" style="margin: 0 auto; width:1180px; height:30px; position:relative; background-color:black">
<!-- Include page Navigation -->
<ui:insert name="Navigation">
<ui:include src="Navigation.xhtml"/>
</ui:insert>
</div>
<div id="logodiv" style="position:relative; top:35px; left:0px;">
<h:graphicImage alt="Demo edit form" style="position:relative; top:-20px; left:9px;" value="resources/images/logo_linuxz.png" />
</div>
<div id="main" style="margin: 0 auto; width:1190px; height:700px; position:absolute; background-color:transparent; top:105px">
<div id="mainpage" style="margin: 0 auto; width:1190px; height:500px; position:absolute; background-color:transparent; top:80px">
<div id="settingsHashMap" style="width:350px; height:400px; position:absolute; background-color:r; top:20px; left:1px">
<h:form id="test">
<p:barChart id="basic" value="#{LinuxController.categoryModel}" legendPosition="ne"
title="Basic Bar Chart" min="0" max="200" style="height:300px"/>
<p:barChart id="horizontal" value="#{LinuxController.categoryModel}" legendPosition="se" style="height:300px"
title="Horizontal Bar Chart" orientation="horizontal" min="0" max="200"/>
<p:barChart id="stacked" value="#{LinuxController.categoryModel}" legendPosition="ne" style="height:300px"
title="Stacked Bar Chart" stacked="true" barMargin="50" min="0" max="300"/>
</h:form>
</div>
</div>
</div>
</h:body>
</html>
import org.glassfish.osgicdi.OSGiService;
import org.primefaces.model.chart.CartesianChartModel;
import org.primefaces.model.chart.ChartSeries;
// Update form example
@Named("LinuxController")
@SessionScoped
public class Linux implements Serializable {
private CartesianChartModel categoryModel;
public Linux() {
createCategoryModel();
}
public CartesianChartModel getCategoryModel() {
return categoryModel;
}
private void createCategoryModel() {
categoryModel = new CartesianChartModel();
ChartSeries boys = new ChartSeries();
boys.setLabel("Boys");
boys.set("2004", 120);
boys.set("2005", 100);
boys.set("2006", 44);
boys.set("2007", 150);
boys.set("2008", 25);
ChartSeries girls = new ChartSeries();
girls.setLabel("Girls");
girls.set("2004", 52);
girls.set("2005", 60);
girls.set("2006", 110);
girls.set("2007", 135);
girls.set("2008", 120);
categoryModel.addSeries(boys);
categoryModel.addSeries(girls);
}
}
当我尝试访问JSF页面时,页面是空。我在Glassfish日志文件中收到此错误:
When I try to access the JSF page the page is empty. I get this error in Glassfish log file:
[#|2012-06-06T20:53:47.931+0300|WARNING|glassfish3.1.2|org.apache.catalina.connector.Request|_ThreadID=321;_ThreadName=Thread-2;|PWC4011: Unable to set request character encoding to UTF-8 from context /test, because request parameters have already been read, or ServletRequest.getReader() has already been called|#]
[#|2012-06-06T20:53:48.880+0300|WARNING|glassfish3.1.2|org.apache.catalina.connector.Request|_ThreadID=323;_ThreadName=Thread-2;|PWC4011: Unable to set request character encoding to UTF-8 from context /test, because request parameters have already been read, or ServletRequest.getReader() has already been called|#]
[#|2012-06-06T20:53:52.714+0300|WARNING|glassfish3.1.2|org.apache.catalina.connector.Request|_ThreadID=321;_ThreadName=Thread-2;|PWC4011: Unable to set request character encoding to UTF-8 from context /test, because request parameters have already been read, or ServletRequest.getReader() has already been called|#]
[#|2012-06-06T20:53:56.434+0300|WARNING|glassfish3.1.2|org.apache.catalina.connector.Request|_ThreadID=324;_ThreadName=Thread-2;|PWC4011: Unable to set request character encoding to UTF-8 from context /test, because request parameters have already been read, or ServletRequest.getReader() has already been called|#]
[#|2012-06-06T20:53:57.591+0300|WARNING|glassfish3.1.2|org.apache.catalina.connector.Request|_ThreadID=322;_ThreadName=Thread-2;|PWC4011: Unable to set request character encoding to UTF-8 from context /test, because request parameters have already been read, or ServletRequest.getReader() has already been called|#]
[#|2012-06-06T20:54:25.828+0300|WARNING|glassfish3.1.2|org.apache.catalina.connector.Request|_ThreadID=323;_ThreadName=Thread-2;|PWC4011: Unable to set request character encoding to UTF-8 from context /test, because request parameters have already been read, or ServletRequest.getReader() has already been called|#]
[#|2012-06-06T20:54:26.912+0300|WARNING|glassfish3.1.2|org.apache.catalina.connector.Request|_ThreadID=321;_ThreadName=Thread-2;|PWC4011: Unable to set request character encoding to UTF-8 from context /test, because request parameters have already been read, or ServletRequest.getReader() has already been called|#]
[#|2012-06-06T20:54:28.010+0300|WARNING|glassfish3.1.2|org.apache.catalina.connector.Request|_ThreadID=324;_ThreadName=Thread-2;|PWC4011: Unable to set request character encoding to UTF-8 from context /test, because request parameters have already been read, or ServletRequest.getReader() has already been called|#]
我如何解决这个问题?我想这可能是由POM配置引起的?
How I can fix this problem? I suppose that this maybe caused by POM configuration?
推荐答案
JSF / Facelets默认使用UTF-8已经在恢复过程中设置了视图,但是PrimeFaces ajax视图处理程序在视图恢复之前尝试访问请求参数,因此将使用服务器的默认字符编码,而不是ISO-8859-1。您需要将以下条目添加到 /WEB-INF/glassfish-web.xml的
文件,指示Glassfish服务器也使用UTF-8:< glassfish-web-app>
中
JSF/Facelets uses UTF-8 by default already which get set during restoring the view, however the PrimeFaces ajax view handler tries to access a request parameter before the view get restored, so the server's default character encoding will be used instead which is ISO-8859-1. You need to add the following entry to the <glassfish-web-app>
of your /WEB-INF/glassfish-web.xml
file to instruct the Glassfish server to use UTF-8 as well:
<parameter-encoding default-charset="UTF-8"/>
参见:
- 通过PrimeFaces输入组件检索到的Unicode输入已损坏
- Unicode input retrieved via PrimeFaces input components become corrupted
See also:
这篇关于无法从上下文将请求字符编码设置为UTF-8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!