title: JBWEB004052: Exception occurred when flushing data
body: <p>I had this running on tomcat using just notepad to edit but I can not get it to run in eclipse deploying to wildfly. Please help!  </p>
  
  <p>This is the error kind of long:</p>
  
  <pre><code>18:26:23,509 ERROR [io.undertow.request] (default task-100) UT005023: Exception handling request to /ADTF_WebProj/BasicAjax/Basic.jsp: javax.servlet.ServletException: java.lang.IllegalStateException: JBWEB004052: Exception occurred when flushing data
      at javax.faces.webapp.FacesServlet.service(FacesServlet.java:659) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
      at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
      at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:61) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
      at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
      at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
      at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
      at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:113) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
      at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:56) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
      at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
      at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:45) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
      at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:61) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
      at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:58) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
      at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:70) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
      at io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:76) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
      at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
      at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
      at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
      at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
      at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:240) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
      at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:227) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
      at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:73) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
      at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:146) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
      at io.undertow.server.Connectors.executeRootHandler(Connectors.java:177) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
      at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:727) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_71]
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_71]
      at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_71]
  Caused by: java.lang.RuntimeException: java.lang.IllegalStateException: JBWEB004052: Exception occurred when flushing data
      at io.undertow.servlet.spec.RequestDispatcherImpl.forward(RequestDispatcherImpl.java:182) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
      at com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:633) [jsf-impl-2.2.6-jbossorg-4.jar:]
      at com.sun.faces.application.view.JspViewHandlingStrategy.executePageToBuildView(JspViewHandlingStrategy.java:363) [jsf-impl-2.2.6-jbossorg-4.jar:]
      at com.sun.faces.application.view.JspViewHandlingStrategy.buildView(JspViewHandlingStrategy.java:153) [jsf-impl-2.2.6-jbossorg-4.jar:]
      at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:99) [jsf-impl-2.2.6-jbossorg-4.jar:]
      at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) [jsf-impl-2.2.6-jbossorg-4.jar:]
      at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219) [jsf-impl-2.2.6-jbossorg-4.jar:]
      at javax.faces.webapp.FacesServlet.service(FacesServlet.java:647) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
      ... 26 more
  Caused by: java.lang.IllegalStateException: JBWEB004052: Exception occurred when flushing data
      at org.apache.jasper.runtime.PageContextImpl.release(PageContextImpl.java:194) [jastow-1.0.0.Final.jar:1.0.0.Final]
      at org.apache.jasper.runtime.JspFactoryImpl.internalReleasePageContext(JspFactoryImpl.java:115) [jastow-1.0.0.Final.jar:1.0.0.Final]
      at org.apache.jasper.runtime.JspFactoryImpl.releasePageContext(JspFactoryImpl.java:74) [jastow-1.0.0.Final.jar:1.0.0.Final]
      at org.apache.jsp.BasicAjax.Basic_jsp._jspService(Basic_jsp.java:122)
      at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:69) [jastow-1.0.0.Final.jar:1.0.0.Final]
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) [jboss-servlet-api_3.1_spec-1.0.0.Final.jar:1.0.0.Final]
      at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:366) [jastow-1.0.0.Final.jar:1.0.0.Final]
      at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:326) [jastow-1.0.0.Final.jar:1.0.0.Final]
      at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:259) [jastow-1.0.0.Final.jar:1.0.0.Final]
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) [jboss-servlet-api_3.1_spec-1.0.0.Final.jar:1.0.0.Final]
      at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
      at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:61) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
      at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
      at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
      at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
      at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
      at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:229) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
      at io.undertow.servlet.handlers.ServletInitialHandler.dispatchToPath(ServletInitialHandler.java:172) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
      at io.undertow.servlet.spec.RequestDispatcherImpl.forward(RequestDispatcherImpl.java:159) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
      ... 33 more
  Caused by: java.io.IOException: JBWEB004226: Stream closed
      at org.apache.jasper.runtime.JspWriterImpl.ensureOpen(JspWriterImpl.java:190) [jastow-1.0.0.Final.jar:1.0.0.Final]
      at org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:116) [jastow-1.0.0.Final.jar:1.0.0.Final]
      at org.apache.jasper.runtime.PageContextImpl.release(PageContextImpl.java:191) [jastow-1.0.0.Final.jar:1.0.0.Final]
      ... 51 more
  </code></pre>
  
  <p>I am pretty sure the error is in the following code in basic.jsp:</p>
  
  <pre><code>&lt;%@page contentType="text/xml"%&gt;&lt;%@page pageEncoding="UTF-8"%&gt;&lt;%
  
  response.addHeader("Cache-Control","max-age=1, must-revalidate");
  
  // --- Database connection ---
  String Path = request.getServletPath().replaceAll("[^\\/\\\\]*$",""); // Relative path to script directory ending with "/"
  java.sql.Connection Conn = null;
  java.sql.Statement Cmd = null;
  try {
     Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
     Conn = java.sql.DriverManager.getConnection("jdbc:oracle:thin:&lt;url&gt;:&lt;port&gt;:&lt;sid&gt;", "&lt;username&gt;", "&lt;password&gt;");
        Cmd = Conn.createStatement();
     } catch (Exception e) {
     out.print("Error is:" + e);
     out.close();
     throw new Exception("");
     }
  
  try {
     StringBuffer S = new StringBuffer();
     S=null;
     java.sql.ResultSet R = Cmd.executeQuery("SELECT * FROM GRIDDATA WHERE GRIDID = 11");
  
     S.append("&lt;Grid&gt;&lt;Body&gt;&lt;B&gt;");
     while(R.next()){     
       S.append("&lt;I, GRIDID='" + R.getString(1) + "'"
              + " id='" + R.getString(2) + "'"
              + " DRAWING='" + R.getString(3) + "'"
              + " TITLE='" + R.getString(4) + "'"
              + "/&gt;");
       }
     S.append("&lt;/B&gt;&lt;/Body&gt;&lt;/Grid&gt;");
     out.print(S.toString());
     R.close();
  }
  catch(Exception ex){
     out.print("Error in getting data !&lt;br&gt;");
     out.print(ex.getMessage());
     }
  %&gt;
  </code></pre>