title: Cannot create a session after the response has been committed
body: <p>Opening the JSF page gives me the following exception:</p>
  
  <blockquote>
    <p>Caused by: java.lang.IllegalStateException: Cannot create a session after the response has been committed</p>
  </blockquote>
  
  <p>Here is the JSF code:</p>
  
  <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;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"&gt;
      &lt;h:head&gt;
          &lt;h:outputStylesheet name="master_c.css" library="css" /&gt;
          &lt;title&gt;Quotes&lt;/title&gt;
      &lt;/h:head&gt;
      &lt;h:body styleClass="venue product"&gt;
          &lt;h:form&gt;
              &lt;div id="wrapper"&gt;
                  &lt;div id="content"&gt;
                      &lt;h2&gt;&lt;a href="#"&gt;&lt;img src="/Webify/static/image/venue-large.png" /&gt;&lt;/a&gt;&lt;/h2&gt;
                      &lt;ul id="calltoaction"&gt;
                          &lt;li id="cta-map"&gt;&lt;a href="#"&gt;MAP&lt;/a&gt;&lt;/li&gt;
                          &lt;li id="cta-download" class="addthis_toolbox addthis_share_btn"&gt;&lt;a href="#"&gt;qmobile&lt;/a&gt;&lt;/li&gt;
                      &lt;/ul&gt;
                      &lt;!-- calltoaction --&gt;
                      &lt;div class="sec-content"&gt;
                          &lt;ul id="techspecs" class="mobile"&gt;
                              &lt;li&gt;&lt;/li&gt;
                              &lt;li&gt;&lt;img height="50" width="79" alt="QMobile Kâşif" src="/Webify/static/image/mac-universal.png" /&gt;&lt;b&gt;QMobile&lt;/b&gt;&lt;br /&gt;Bahara&lt;br /&gt;Pahli baar&lt;/li&gt;
                              &lt;li&gt;Lorem Ispum Lorem Ispum Lorem Ispum Lorem Ispum Lorem Ispum Lorem Ispum Lorem Ispum Lorem Ispum Lorem Ispum Lorem Ispum Lorem Ispum Lorem Ispum&lt;/li&gt;
                          &lt;/ul&gt;
                          &lt;!-- techspecs --&gt;
                          &lt;ul id="sc-reviews" class="mobile"&gt;
                              &lt;li&gt;&lt;a href="#"&gt;&lt;img height="35" width="200" alt="Android" src="/Webify/static/image/text_android.png" /&gt;&lt;/a&gt;&lt;/li&gt;
                              &lt;li&gt;&lt;a href="#"&gt;&lt;img height="35" width="200" alt="IPhone" src="/Webify/static/image/text_iphone.png" /&gt;&lt;/a&gt;&lt;/li&gt;
                              &lt;li&gt;&lt;a href="#"&gt;&lt;img height="35" width="200" alt="BlackBerry" src="/Webify/static/image/text_blackberry.png" /&gt;&lt;/a&gt;&lt;/li&gt;
                              &lt;li&gt;&lt;a href="#"&gt;Find More...&lt;/a&gt;&lt;/li&gt;
                          &lt;/ul&gt;
                          &lt;!-- sc-reviews --&gt;
                      &lt;/div&gt;
  
                      &lt;div class="prim-content"&gt;
                          &lt;!-- Page Heading --&gt;
                          &lt;div id="sec-navigation"&gt;
                              &lt;h3 style="margin-left: 10px;"&gt;&lt;/h3&gt;
                          &lt;/div&gt;
  
                          &lt;div id="wall"&gt;
                              &lt;!-- bricks end --&gt;
                          &lt;/div&gt;
                          &lt;!-- wall end --&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/h:form&gt;
      &lt;/h:body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Here is the stacktrace:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>How is this problem caused and how can I solve it? I am using Mojarra 2.1.2. </p>