JSFページを開くと、次の例外が発生します。
原因:Java.lang.IllegalStateException:応答がコミットされた後でセッションを作成できません
JSFコードは次のとおりです。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
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.prime.com.tr/ui">
<h:head>
<h:outputStylesheet name="master_c.css" library="css" />
<title>Quotes</title>
</h:head>
<h:body styleClass="venue product">
<h:form>
<div id="wrapper">
<div id="content">
<h2><a href="#"><img src="/Webify/static/image/venue-large.png" /></a></h2>
<ul id="calltoaction">
<li id="cta-map"><a href="#">MAP</a></li>
<li id="cta-download" class="addthis_toolbox addthis_share_btn"><a href="#">qmobile</a></li>
</ul>
<!-- calltoaction -->
<div class="sec-content">
<ul id="techspecs" class="mobile">
<li></li>
<li><img height="50" width="79" alt="QMobile Kâşif" src="/Webify/static/image/mac-universal.png" /><b>QMobile</b><br />Bahara<br />Pahli baar</li>
<li>Lorem Ispum Lorem Ispum Lorem Ispum Lorem Ispum Lorem Ispum Lorem Ispum Lorem Ispum Lorem Ispum Lorem Ispum Lorem Ispum Lorem Ispum Lorem Ispum</li>
</ul>
<!-- techspecs -->
<ul id="sc-reviews" class="mobile">
<li><a href="#"><img height="35" width="200" alt="Android" src="/Webify/static/image/text_Android.png" /></a></li>
<li><a href="#"><img height="35" width="200" alt="IPhone" src="/Webify/static/image/text_iphone.png" /></a></li>
<li><a href="#"><img height="35" width="200" alt="BlackBerry" src="/Webify/static/image/text_blackberry.png" /></a></li>
<li><a href="#">Find More...</a></li>
</ul>
<!-- sc-reviews -->
</div>
<div class="prim-content">
<!-- Page Heading -->
<div id="sec-navigation">
<h3 style="margin-left: 10px;"></h3>
</div>
<div id="wall">
<!-- bricks end -->
</div>
<!-- wall end -->
</div>
</div>
</div>
</h:form>
</h:body>
</html>
これがスタックトレースです:
Sep 16, 2011 1:45:40 PM com.Sun.faces.application.view.FaceletViewHandlingStrategy handleRenderException
SEVERE: Error Rendering View[/streamfaces.xhtml]
Java.lang.IllegalStateException: Cannot create a session after the response has been committed
at org.Apache.catalina.connector.Request.doGetSession(Request.Java:2734)
at org.Apache.catalina.connector.Request.getSession(Request.Java:2244)
at org.Apache.catalina.connector.RequestFacade.getSession(RequestFacade.Java:899)
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:418)
at com.Sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.Java:131)
at com.ocpsoft.pretty.faces.application.PrettyViewHandler.renderView(PrettyViewHandler.Java:163)
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.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.Java:304)
at org.Apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.Java:210)
at org.Apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.Java:240)
at org.Apache.catalina.core.StandardContextValve.invoke(StandardContextValve.Java:164)
at org.Apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.Java:462)
at org.Apache.catalina.core.StandardHostValve.invoke(StandardHostValve.Java:164)
at org.Apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.Java:100)
at org.Apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.Java:563)
at org.Apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.Java:118)
at org.Apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.Java:399)
at org.Apache.coyote.http11.Http11Processor.process(Http11Processor.Java:317)
at org.Apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.Java:204)
at org.Apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.Java:182)
at org.Apache.Tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.Java:311)
at Java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.Java:886)
at Java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.Java:908)
at Java.lang.Thread.run(Thread.Java:619)
Sep 16, 2011 1:45:40 PM com.Sun.faces.context.ExceptionHandlerImpl throwIt
INFO: Exception when handling error trying to reset the response.
Java.lang.IllegalStateException: Cannot create a session after the response has been committed
at org.Apache.catalina.connector.Request.doGetSession(Request.Java:2734)
at org.Apache.catalina.connector.Request.getSession(Request.Java:2244)
at org.Apache.catalina.connector.RequestFacade.getSession(RequestFacade.Java:899)
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:418)
at com.Sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.Java:131)
at com.ocpsoft.pretty.faces.application.PrettyViewHandler.renderView(PrettyViewHandler.Java:163)
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.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.Java:304)
at org.Apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.Java:210)
at org.Apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.Java:240)
at org.Apache.catalina.core.StandardContextValve.invoke(StandardContextValve.Java:164)
at org.Apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.Java:462)
at org.Apache.catalina.core.StandardHostValve.invoke(StandardHostValve.Java:164)
at org.Apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.Java:100)
at org.Apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.Java:563)
at org.Apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.Java:118)
at org.Apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.Java:399)
at org.Apache.coyote.http11.Http11Processor.process(Http11Processor.Java:317)
at org.Apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.Java:204)
at org.Apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.Java:182)
at org.Apache.Tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.Java:311)
at Java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.Java:886)
at Java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.Java:908)
at Java.lang.Thread.run(Thread.Java:619)
Sep 16, 2011 1:45:40 PM com.Sun.faces.renderkit.RenderKitUtils renderHtmlErrorPage
WARNING: JSF1087: Unable to generate Facelets error page as the response has already been committed.
Sep 16, 2011 1:45:40 PM com.Sun.faces.renderkit.RenderKitUtils renderHtmlErrorPage
SEVERE: javax.faces.FacesException: Cannot create a session after the response has been committed
javax.faces.FacesException: Cannot create a session after the response has been committed
at com.Sun.faces.context.ExceptionHandlerImpl.handle(ExceptionHandlerImpl.Java:141)
at com.Sun.faces.lifecycle.Phase.doPhase(Phase.Java:119)
at com.Sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.Java:139)
at javax.faces.webapp.FacesServlet.service(FacesServlet.Java:594)
at org.Apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.Java:304)
at org.Apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.Java:210)
at org.Apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.Java:240)
at org.Apache.catalina.core.StandardContextValve.invoke(StandardContextValve.Java:164)
at org.Apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.Java:462)
at org.Apache.catalina.core.StandardHostValve.invoke(StandardHostValve.Java:164)
at org.Apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.Java:100)
at org.Apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.Java:563)
at org.Apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.Java:118)
at org.Apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.Java:399)
at org.Apache.coyote.http11.Http11Processor.process(Http11Processor.Java:317)
at org.Apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.Java:204)
at org.Apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.Java:182)
at org.Apache.Tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.Java:311)
at Java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.Java:886)
at Java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.Java:908)
at Java.lang.Thread.run(Thread.Java:619)
Caused by: Java.lang.IllegalStateException: Cannot create a session after the response has been committed
at org.Apache.catalina.connector.Request.doGetSession(Request.Java:2734)
at org.Apache.catalina.connector.Request.getSession(Request.Java:2244)
at org.Apache.catalina.connector.RequestFacade.getSession(RequestFacade.Java:899)
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:418)
at com.Sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.Java:131)
at com.ocpsoft.pretty.faces.application.PrettyViewHandler.renderView(PrettyViewHandler.Java:163)
at com.Sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.Java:121)
at com.Sun.faces.lifecycle.Phase.doPhase(Phase.Java:101)
... 19 more
この問題の原因と解決方法を教えてください。 Mojarra 2.1.2を使用しています。
[解決済み]
この問題の診断には数日かかりましたが、ようやくこの問題を解決することができました。
実際には@ViewScoped
であり、シリアル化されていない管理プロパティDAOオブジェクトがあります。したがって、ビューがレンダリングされた後、faceletsもこの例外を生成しますが、JSFビューはすでにレンダリングされているため、この例外が表示されました。
Solution:@ViewScoped
Beanでシリアル化されたすべてのオブジェクトを作成し、シリアライズされていない "transient"をマークします。私の場合は、JSF @ViewScoped
のDAOオブジェクトでした。
その理由は:
HttpSession
に格納しますしたがって、解決策は、Facelet(/ JSP)ページが印刷される前にセッションを作成することです。大まかな例は次のようになります。
@PostConstruct
void initialiseSession() {
FacesContext.getCurrentInstance().getExternalContext().getSession(true);
}
/ napu
これをweb.xmlに入れて、私のアプリの1つの問題を解決します。
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
奇妙なのは、web.xmlでこのブードゥーを必要としないこの同じガラス魚インスタンスでホストされている他のいくつかのアプリケーションがあることです。
私はこれが解決策ではないことを強く信じたいのですが、この特定のアプリがそれを必要とし、他の人が必要としない理由は私には意味がありません。しかし今のところそれは機能します。
それは私にも起こりました。
以前はMojarra 2.1.13を使用していましたが、それを2.1.29に更新すると、コードを変更せずに問題が自動的に解決しました。