jsf facelet波斯语字符编码错误

jsf facelet波斯语字符编码错误,jsf,encoding,filter,Jsf,Encoding,Filter,我用jsf和netbeans 7.3.1开发了一个java应用程序,但我的角色保存不正确。我查看请求变量,发现我的角色没有正确地显示在请求对象中 我的Jsf示例: <html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://xmlns.jcp.org/jsf/facelets" xmlns:h="http://xmlns.jcp.org/jsf/html" xmlns:f="http://xml

我用jsf和netbeans 7.3.1开发了一个java应用程序,但我的角色保存不正确。我查看请求变量,发现我的角色没有正确地显示在请求对象中

我的Jsf示例:

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:f="http://xmlns.jcp.org/jsf/core">

    <ui:composition template="/template.xhtml">
        <ui:define name="title">
            <h:outputText value="#{bundle.CreateTblAccessTitle}"></h:outputText>
        </ui:define>
        <ui:define name="body">
            <h:panelGroup id="messagePanel" layout="block">
                <h:messages errorStyle="color: red" infoStyle="color: green" layout="table"/>
            </h:panelGroup>
            <h:form>
                <h:panelGrid columns="2">
                    <h:outputLabel value="#{bundle.CreateTblAccessLabel_id}" for="id" />
                    <h:inputText id="id" value="#{tblAccessController.selected.id}" title="#{bundle.CreateTblAccessTitle_id}" required="true" requiredMessage="#{bundle.CreateTblAccessRequiredMessage_id}"/>
                    <h:outputLabel value="#{bundle.CreateTblAccessLabel_userName}" for="userName" />
                    <h:inputText id="userName" value="#{tblAccessController.selected.userName}" title="#{bundle.CreateTblAccessTitle_userName}" />
                    <h:outputLabel value="#{bundle.CreateTblAccessLabel_userTypeId}" for="userTypeId" />
                    <h:selectOneMenu id="userTypeId" value="#{tblAccessController.selected.userTypeId}" title="#{bundle.CreateTblAccessTitle_userTypeId}" >
                        <f:selectItems value="#{tblUserTypeController.itemsAvailableSelectOne}"/>
                    </h:selectOneMenu>
                    <h:outputLabel value="#{bundle.CreateTblAccessLabel_formId}" for="formId" />
                    <h:selectOneMenu id="formId" value="#{tblAccessController.selected.formId}" title="#{bundle.CreateTblAccessTitle_formId}" required="true" requiredMessage="#{bundle.CreateTblAccessRequiredMessage_formId}">
                        <f:selectItems value="#{tblFormController.itemsAvailableSelectOne}"/>
                    </h:selectOneMenu>
                    <h:outputLabel value="#{bundle.CreateTblAccessLabel_activitesId}" for="activitesId" />
                    <h:selectOneMenu id="activitesId" value="#{tblAccessController.selected.activitesId}" title="#{bundle.CreateTblAccessTitle_activitesId}" required="true" requiredMessage="#{bundle.CreateTblAccessRequiredMessage_activitesId}">
                        <f:selectItems value="#{tblAccessActivitiesController.itemsAvailableSelectOne}"/>
                    </h:selectOneMenu>
                </h:panelGrid>
                <br />
                <h:commandLink action="#{tblAccessController.create}" value="#{bundle.CreateTblAccessSaveLink}" />
                <br />
                <br />
                <h:commandLink action="#{tblAccessController.prepareList}" value="#{bundle.CreateTblAccessShowAllLink}" immediate="true"/>
                <br />
                <br />
                <h:link outcome="/index" value="#{bundle.CreateTblAccessIndexLink}"/>
            </h:form>
        </ui:define>
    </ui:composition>

</html>
My Template.xhtml

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
      xmlns:h="http://xmlns.jcp.org/jsf/html">
    <h:head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title><ui:insert name="title">Default Title</ui:insert></title>
        <h:outputStylesheet name="css/jsfcrud.css"/>
    </h:head>

    <h:body>
        <h1>
            <ui:insert name="title">Default Title</ui:insert>
        </h1>
        <p>
            <ui:insert name="body">Default Body</ui:insert>
        </p>
    </h:body>
</html>

默认标题
默认标题

默认主体

My web.xml

<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Development</param-value>
    </context-param>
    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>/faces/*</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
        <welcome-file>faces/index.xhtml</welcome-file>
    </welcome-file-list>
    <filter>
        <filter-name>encodingFilter</filter-name>
        <filter-class>business.EncodingFilter</filter-class>
        <init-param>
                <param-name>requestEncoding</param-name>
                <param-value>UTF-8</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>encodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <jsp-config>
        <jsp-property-group>
            <url-pattern>*.xhtml</url-pattern>
            <page-encoding>UTF-8</page-encoding>
        </jsp-property-group>
    </jsp-config>
</web-app>

javax.faces.PROJECT_阶段
发展
Facesservlet
javax.faces.webapp.FacesServlet
1.
Facesservlet
/面孔/*
30
faces/index.xhtml
编码滤波器
商业编码过滤器
请求编码
UTF-8
编码滤波器
/*
*.xhtml
UTF-8

有什么问题?我该怎么解决呢?

一切看起来都很好!您应检查以下各项:

a) 检查您的Glassfish资源是否包含以下内容:

<property name="useUnicode" value="true"/>
<property name="characterEncoding" value="UTF8"/>

乍一看一切正常(除了在过滤器中操纵
响应
,这是完全不必要的,我会去掉这些行;另外
destroy()
中的异常是错误的,请删除整行),因此您的问题可能是由其他地方引起的。你到底是如何断定这些角色被破坏的?您是使用
System.out.println()将它们打印到IDE控制台还是什么?如果是这样的话,您确定控制台已配置为使用UTF-8打印这些字符吗?不,我在代码中添加了断点,并监视类的值。请求对象中的值不正确。当我用workbench直接将值存储在数据库中时,它会在资源管理器中正确显示,但当我用表单保存数据时,它是不正确的。我用intellij idea用tomcat和hibernate创建了同一个项目,其中没有问题。一切都好。有人知道问题出在哪里吗。我的netbeans项目应用程序服务器是glassfish
<property name="useUnicode" value="true"/>
<property name="characterEncoding" value="UTF8"/>
ALTER DATABASE dbname DEFAULT CHARACTER SET utf8;

USE dbname;

ALTER TABLE tblname CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;