JSF错误 - IllegalStateException:PWC3999:在提交响应后无法创建会话

时间:2012-08-09 05:47:13

标签: java jsf java-ee jsf-2 facelets

我是JSF的新手,我正在构建一个用facelets创建的应用程序。
这是我的模板
master.xhtml

<body id="body">
 <form id="frmmaster">
        <div id="pg-nav-bg">
            <div class="wrapper clear">
                <div class="footer clear">
                    <div class="footerContent">Help Des</div>
                </div>
                <div id="pg-nav">
                    <ul class="nav sf-js-enabled">
                        <li class="page_item" id="liHomr">
                            <a href="#" title="Home">Home</a>
                        </li>
                        <li class="page_item" id="liFreeSearch">
                            <a href="#" title="Free Search" >Free Search</a>  
                        </li>
                        <li class="page_item" id="liMasterSearch">      
                            <a href="#"  title="Search">Search</a> 
                        </li>
                        <li class="page_item" id="liAdvanceSearch">
                            <a href="#" title="Advanced Search">Advanced Search</a> 
                        </li>
                        <li class="page_item" id="liCharts">
                            <a href="#" title="Charts" >Charts</a>  <!-- 
                        </li>
                    </ul>
                </div>
            </div>
        </div>
        <div class="wrapper clear">
            <div class="Welcome ">
                <div class="welcome">
                     Welcome! &nbsp;<strong>Searcher</strong>
                    &nbsp; | &nbsp;
                    <strong >
                        [ <a title="Change Password" href="" style="color: #FFFFFF;">Change Password</a> ]
                        [ <h:commandLink id="lbSignOut" value="Sign Out" onclick="lbSignOut_Click"  styleClass="color: #FFFFFF;"></h:commandLink> ]
                    </strong>
                </div>
                <br class="clear" />
                <div>
                    <label id="lblMessage"></label>
                </div>
            </div>
        </div>
        <div class="wrapper big" >
            <div id="header" class="clear">
                <img src="../../images/logo.png" class="image" alt=""/>
                <div class="logo">
                    <div id="title" >M - 11</div>
                    <div id="version">V 0.8</div>
                    <div id="description">Helps in finding the right person</div>
                </div>
            </div>
            <!-- Here I included facelet -->
            <ui:include src="../SearchPages/MasterSearch.xhtml"/> 

        </div>
   </form>
</body>

</html>

现在下面的文件是我在master.xhtml中包含的我的合成文件i-e

MasterSearch.xhtml

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core">
<div id="sidebar">
            <ul>
                <li class="widget">
                    <table>   
                    <h:form> 
                        <tr><td>Service Number</td>
                            <td>
                            <h:inputText id="txtMasterServiceNumber" styleClass="text-box" value="#{masterSearch.serviceNumber}" requiredMessage="enter value">
                            <f:validateRegex pattern="[A-Za-z0-9]{1,40}"/>
                            </h:inputText>
                            <h:message for="txtMasterServiceNumber" />

                            </td>
                        </tr>
                        <tr>
                            <td>Rank</td>
                            <td><h:selectOneMenu id="cboMasterRank" value="#{masterSearch.rank}" styleClass="select-field">
                                            <f:selectItem itemLabel="--Please Select--" itemValue="medium" />
                                            <f:selectItem itemLabel="A" itemValue="medium" />
                                            <f:selectItem itemLabel="B" itemValue="basic" />
                                            <f:selectItem itemLabel="C" itemValue="premium" />
                                            </h:selectOneMenu></td>
                        </tr>
                        <tr>
                            <td>Full Name</td>
                            <td>
                            <h:inputText id="txtMasterFullName" styleClass="text-box" value="#{masterSearch.fullName}" validatorMessage="Please enter a valid name.">
                            <f:validateRegex pattern="^([A-Za-z])*$" />
                            <h:message for="txtMasterFullName" styleClass="Error" /></h:inputText>
                            </td>
                        </tr>
                        <tr>
                            <td>CNIC Number</td>
                            <td><h:inputText id="txtMasterCNIC" value="#{masterSearch.CNICNumber}"  styleClass="text-box">
                            <f:validateRegex pattern="^([A-Za-z])*$" />
                            <h:message for="txtMasterFullName" styleClass="Error" />
                            </h:inputText>
                            </td>
                        </tr>
                        <tr>
                            <td>Phone No.</td>
                            <td><h:inputText id="txtMasterPhoneNo" value="#{masterSearch.phoneNumber}"  styleClass="text-box"></h:inputText>
                            </td>
                        </tr>
                        <tr>
                            <td>Email Address</td>
                            <td><h:inputText id="txtMasterEmail" value="#{masterSearch.emailAddress}"  styleClass="text-box"></h:inputText>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2" align="right">
                            <h:commandButton id="btnMasterSearch"  type="submit" value="Search" styleClass="submitButton"  action="#{masterSearch.findPerson}"></h:commandButton>
                            </td>
                        </tr>
                        </h:form>
                   </table>
                </li>
            </ul>
                <img src="../../images/loader.gif" alt="" style="vertical-align:middle;margin:2px;"/>Loading...
        </div>

    </div>
    <script src="../../Scripts/searchexternal.js" type="text/javascript"></script>

MasterSearch.java这是一个bean

public class MasterSearch {

    long serviceNumber;
    String rank;
    String fullName;
    String CNICNumber;
    String phoneNumber;
    String emailAddress;

    public long getServiceNumber() {
        return serviceNumber;
    }
    public void setServiceNumber(long serviceNumber) {
        this.serviceNumber = serviceNumber;
    }
    public String getRank() {
        return rank;
    }
    public void setRank(String rank) {
        this.rank = rank;
    }
    public String getFullName() {
        return fullName;
    }
    public void setFullName(String fullName) {
        this.fullName = fullName;
    }
    public String getCNICNumber() {
        return CNICNumber;
    }
    public void setCNICNumber(String cNICNumber) {
        CNICNumber = cNICNumber;
    }
    public String getPhoneNumber() {
        return phoneNumber;
    }
    public void setPhoneNumber(String phoneNumber) {
        this.phoneNumber = phoneNumber;
    }
    public String getEmailAddress() {
        return emailAddress;
    }
    public void setEmailAddress(String emailAddress) {
        this.emailAddress = emailAddress;
    }

    public String findPerson(){

        return "personfound";

    }

}

faces-config.xml中

<?xml version="1.0" encoding="UTF-8"?>

<faces-config
    xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"

    version="2.0">

    <application>
        <el-resolver>
            org.springframework.web.jsf.el.SpringBeanFacesELResolver
        </el-resolver>
    </application>

<managed-bean>
    <managed-bean-name>masterSearch</managed-bean-name>
        <managed-bean-class>
            MasterSearch
        </managed-bean-class>
    <managed-bean-scope>request</managed-bean-scope>
</managed-bean>

<managed-bean>
    <managed-bean-name>masterResult</managed-bean-name>
        <managed-bean-class>
            com.delta.resultbeans.MasterSearchResult
        </managed-bean-class>
    <managed-bean-scope>request</managed-bean-scope>
</managed-bean>

<navigation-rule>
    <description>Navigation from the MasterSearch</description>
    <from-view-id>/WebPages/SearchPages/MasterSearch.xhtml</from-view-id>
    <navigation-case>
        <from-outcome>personfound</from-outcome>
        <to-view-id>/WebPages/SearchPages/found.jsp</to-view-id>
    </navigation-case>
    <navigation-case>
        <from-outcome>personnotfound</from-outcome>
        <to-view-id>/notfound.jsp</to-view-id>
    </navigation-case>
</navigation-rule>
</faces-config>

现在,当我运行此代码(实际上是masterp.xhtml)时,它显示完美的输出并加载准确但它在控制台i-e中引发异常

SEVERE: Error Rendering View[/WebPages/MasterPage/master.xhtml]
java.lang.IllegalStateException: PWC3999: Cannot create a session after the response has been committed
    at org.apache.catalina.connector.Request.doGetSession(Request.java:2885)
    at org.apache.catalina.connector.Request.getSession(Request.java:2582)
    at org.apache.catalina.connector.RequestFacade.getSession(RequestFacade.java:920)
    at com.sun.faces.context.ExternalContextImpl.getSession(ExternalContextImpl.java:155)
    at com.sun.faces.renderkit.ServerSideStateHelper.writeState(ServerSideStateHelper.java:175)
    at com.sun.faces.renderkit.ResponseStateManagerImpl.writeState(ResponseStateManagerImpl.java:122)
    at com.sun.faces.application.StateManagerImpl.writeState(StateManagerImpl.java:166)
    at com.sun.faces.application.view.WriteBehindStateWriter.flushToWriter(WriteBehindStateWriter.java:225)
    at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:419)
    at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
    at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1542)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
    at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
    at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:849)
    at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:746)
    at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1045)
    at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:228)
    at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
    at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
    at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
    at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
    at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
    at java.lang.Thread.run(Thread.java:722)

INFO: Exception when handling error trying to reset the response.
java.lang.IllegalStateException: PWC3999: Cannot create a session after the response has been committed
    at org.apache.catalina.connector.Request.doGetSession(Request.java:2885)
    at org.apache.catalina.connector.Request.getSession(Request.java:2582)
    at org.apache.catalina.connector.RequestFacade.getSession(RequestFacade.java:920)
    at com.sun.faces.context.ExternalContextImpl.getSession(ExternalContextImpl.java:155)
    at com.sun.faces.renderkit.ServerSideStateHelper.writeState(ServerSideStateHelper.java:175)
    at com.sun.faces.renderkit.ResponseStateManagerImpl.writeState(ResponseStateManagerImpl.java:122)
    at com.sun.faces.application.StateManagerImpl.writeState(StateManagerImpl.java:166)
    at com.sun.faces.application.view.WriteBehindStateWriter.flushToWriter(WriteBehindStateWriter.java:225)
    at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:419)
    at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
    at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1542)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
    at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
    at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:849)
    at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:746)
    at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1045)
    at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:228)
    at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
    at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
    at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
    at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
    at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
    at java.lang.Thread.run(Thread.java:722)

WARNING: StandardWrapperValve[Faces Servlet]: PWC1406: Servlet.service() for servlet Faces Servlet threw exception
java.lang.IllegalStateException: PWC3999: Cannot create a session after the response has been committed
    at org.apache.catalina.connector.Request.doGetSession(Request.java:2885)
    at org.apache.catalina.connector.Request.getSession(Request.java:2582)
    at org.apache.catalina.connector.RequestFacade.getSession(RequestFacade.java:920)
    at com.sun.faces.context.ExternalContextImpl.getSession(ExternalContextImpl.java:155)
    at com.sun.faces.renderkit.ServerSideStateHelper.writeState(ServerSideStateHelper.java:175)
    at com.sun.faces.renderkit.ResponseStateManagerImpl.writeState(ResponseStateManagerImpl.java:122)
    at com.sun.faces.application.StateManagerImpl.writeState(StateManagerImpl.java:166)
    at com.sun.faces.application.view.WriteBehindStateWriter.flushToWriter(WriteBehindStateWriter.java:225)
    at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:419)
    at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
    at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1542)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
    at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
    at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:849)
    at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:746)
    at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1045)
    at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:228)
    at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
    at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
    at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
    at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
    at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
    at java.lang.Thread.run(Thread.java:722)

我认为由于这个原因,它没有提交按钮的动作

<h:commandButton id="btnMasterSearch" type="submit" value="Search" styleClass="submitButton" action="#{masterSearch.findPerson}">中出现了{p> MasterSearch.xhtml。我发现人们遇到了这个问题,但我无法找到并理解一个好的解决方案。
请帮助谢谢

1 个答案:

答案 0 :(得分:10)

这是Mojarra的一个已知错误。它已被报告为问题22152277,并且自Mojarra 2.1.8以来已得到修复。因此,如果升级到至少2.1.8,则此问题应该消失。

此问题的原因可以解释如下:Mojarra正试图尽可能推迟会话创建。该会话应仅在真正需要时创建。其中,当需要编写<h:form>的JSF视图状态时,通常在渲染结束</h:form>期间发生。但是,在相对较大的页面上,在 2KB的书面HTML之后关闭</h:form>出现,那么创建会话为时已晚。要创建会话,服务器即需要设置cookie。但是,要设置cookie,不应该提交响应(cookie需要进入响应头)。默认情况下,服务器配置为刷新每2KB书面HTML的响应。

如上所述,自Mojarra 2.1.8以来,这个问题已得到解决。您可以下载最新版本here