Cannot create a session after the response has bee

2019-09-20 15:55发布

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

Facelet Title

            <f:facet name="header">Books And Authors....</f:facet>
            <h:panelGrid columns="2" rules="cols">



                <h:panelGrid id="pan1" columns="2">

                    <h:outputText value="Select Author"/>
                    <p:selectOneMenu value="#{bean.selectedAuthor}" converter="authorConverter">

                        <f:selectItems value="#{bean.authors}" var="author"
                                       itemLabel="#{author.name}" itemValue="#{author}"/>
                    </p:selectOneMenu>
                    <h:outputText value="Select Books"/>
                    <p:selectManyMenu value="#{bean.selectedBook}" converter="bookConverter">
                        <f:selectItems value="#{bean.books}" var="books"
                                       itemLabel="#{books.name}" itemValue="#{books}"/>
                    </p:selectManyMenu>
                    <p:commandButton value="Add" process="@form:pan1" update="@form:pan1" action="#{bean.add}" />
                </h:panelGrid>

                <h:panelGrid id="pan2" columns="2">
                    <h:outputText value="Enter Book name:"/>
                    <p:inputText value="#{bean.name}"/>

                    <p:commandButton value="Search" process="@form:pan2" update="@form:pan2" action="#{bean.search}"/>
                    <p:commandButton value="Inner Join" process="@form:pan2" update="@form:pan2" action="#{bean.innerJoin}"/>
                    <p:commandButton value="Outer Join" process="@form:pan2" update="@form:pan2" action="#{bean.outerJoin}"/>
                    <p:commandButton value="Fetch Join" process="@form:pan2" update="@form:pan2" action="#{bean.fetchJoin}"/>
                    <p:dataTable value="#{bean.results}" var="authors">

                        <p:column>
                            <f:facet name="header">Author Name</f:facet>
                            #{authors.name}
                        </p:column>
                        <p:column>
                            <f:facet name="header">Book Name</f:facet>
                            <p:dataTable value="#{authors.books}" var="book">
                                <p:column>
                                  #{book.name}
                                </p:column>
                            </p:dataTable>
                        </p:column>
                    </p:dataTable>
                </h:panelGrid>

            </h:panelGrid>
        </p:panel>
    </h:form>
</h:body>

WARNING: JSF1087: Unable to generate Facelets error page as the response has already been committed. SEVERE: javax.faces.FacesException: PWC3999: Cannot create a session after the response has been committed

how can i solve this?

1条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-09-20 16:31

In order to create a session, you (almost always) need to set a Session cookie. That is not possible when the response has already been committed (i.e. the HTTP headers already sent to the client). In this case, it seems that Facelets internally needs a session for something.

how can i solve this?

Create a session earlier in your code. You don't have to put in any session attributes, just make sure that a session exists.

查看更多
登录 后发表回答