title: java.lang.IllegalStateException: Exception occurred when flushing data
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/12327857/exception-occurred-when-flushing-data-what-is-this-and-why-am-i-getting-this">Exception occurred when flushing data . What is this and why am I getting this?</a>  </p>
  </blockquote>
  
  
  
  <p>The following is a snippet from a filter. It gets the client IP , sets the attribute and then chains the request to a servlet.</p>
  
  <pre><code>@Override
   public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain) 
          throws ServletException,IOException {
      String IP = request.getRemoteAddr();
      request.setAttribute("client IP from the filter", IP);
      chain.doFilter(request, response);
  }
  </code></pre>
  
  <p>The following is a snippet from the servlet which has received a filtered request. It gets the IP , stores it as an another attribute and then dispatches the request to <em>index.jsp</em> .</p>
  
  <pre><code>    @Override
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
          throws ServletException, IOException {
      String IP = (String)request.getAttribute("client IP from the filter");
      request.setAttribute("Client IP", IP);
      RequestDispatcher rd = request.getRequestDispatcher("index.jsp");
      rd.forward(request,response);
  }
  </code></pre>
  
  <p>index.jsp , then retrieves the attribute set by the servlet and works upon it. </p>
  
  <p>The servlet is the first thing to run when a website <em>foo.com</em> is first opened. But as I open the website I see this stack trace :</p>
  
  <pre><code>java.lang.IllegalStateException: Exception occurred when flushing data
  at com.google.appengine.runtime.Request.process-d6995d0c305e239e(Request.java)
  at org.apache.jasper.runtime.PageContextImpl.release(PageContextImpl.java:191)
  at org.apache.jasper.runtime.JspFactoryImpl.internalReleasePageContext(JspFactoryImpl.java:118)
  at org.apache.jasper.runtime.JspFactoryImpl.access$100(JspFactoryImpl.java:40)
  at org.apache.jasper.runtime.JspFactoryImpl$PrivilegedReleasePageContext.run(JspFactoryImpl.java:166)
  at java.security.AccessController.doPrivileged(AccessController.java:34)
  at org.apache.jasper.runtime.JspFactoryImpl.releasePageContext(JspFactoryImpl.java:75)
  at org.apache.jsp.index_jsp._jspService(index_jsp.java:139)
  at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
  at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
  at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:390)
  at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
  at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
  at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
  at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
  at org.mortbay.jetty.servlet.Dispatcher.forward(Dispatcher.java:327)
  at org.mortbay.jetty.servlet.Dispatcher.forward(Dispatcher.java:126)
  at Servlets.FW_FirstSite.doGet(FW_FirstSite.java:27)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
  at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
  at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
  at Filters.FirstSiteFilter.doFilter(FirstSiteFilter.java:24)
  at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
  at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
  at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
  at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
  at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
  at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
  at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
  at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
  at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
  at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
  at org.mortbay.jetty.Server.handle(Server.java:326)
  at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
  at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:923)
  at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
  at com.google.tracing.TraceContext$TraceContextRunnable.runInContext(TraceContext.java:452)
  at com.google.tracing.TraceContext$TraceContextRunnable$1.run(TraceContext.java:458)
  at com.google.tracing.TraceContext.runInContext(TraceContext.java:698)
  at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContextNoUnref(TraceContext.java:336)
  at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContext(TraceContext.java:328)
  at com.google.tracing.TraceContext$TraceContextRunnable.run(TraceContext.java:456)
  at java.lang.Thread.run(Thread.java:679)
  Caused by: java.io.IOException: Stream closed
  at org.apache.jasper.runtime.JspWriterImpl.ensureOpen(JspWriterImpl.java:204)
  at org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:115)
  at org.apache.jasper.runtime.PageContextImpl.release(PageContextImpl.java:188)
  ... 43 more
  </code></pre>
  
  <p>Logs suggest that exception occurs  at <strong>Servlets.FW_FirstSite.doGet(FW_FirstSite.java:27)</strong> which is the statement <em>rd.forward(request,response);</em> and at <strong>Filters.FirstSiteFilter.doFilter(FirstSiteFilter.java:24)</strong> which is the statement <em>chain.doFilter(request, response);</em>. </p>
  
  <p>Why do get these exceptions ?</p>