title: java.lang.IllegalStateException: getOutputStream() has already been called for this response when calling JasperReport
body: <p>I am trying iReport/JasperReport in JSF 2
  But while i am generating The PDF i got this error.
  I searched and found some similar problems and solutions, but nothing worked. Sorry for posting the same question again. But I tried all the possible solutions i found, but none worked for me. Please help</p>
  
  <pre><code>java.lang.IllegalStateException: getOutputStream() has already been called for this response
  at org.apache.catalina.connector.Response.getWriter(Response.java:637)
  at org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:214)
  at com.sun.faces.context.ExternalContextImpl.getResponseOutputWriter(ExternalContextImpl.java:723)
  at com.sun.faces.application.view.FaceletViewHandlingStrategy.createResponseWriter(FaceletViewHandlingStrategy.java:1009)
  at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:382)
  at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:124)
  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:305)
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
  at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
  at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
  at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
  at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
  at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
  at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
  at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
  at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
  at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:999)
  at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:565)
  at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:309)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
  at java.lang.Thread.run(Thread.java:722)
  </code></pre>
  
  <p>Following are the functions </p>
  
  <pre><code>public void init() throws IOException, JRException {
      JRBeanCollectionDataSource beanCollectionDataSource = new JRBeanCollectionDataSource(listReportObjects);
      ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
      HttpServletResponse httpServletResponse = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();
      servletOutputStream = httpServletResponse.getOutputStream();
      ServletContext servletContext = (ServletContext) externalContext.getContext();
      String reportLocation = servletContext.getRealPath("/web/ireport/monthlyReport.jasper");
      jasperPrint = JasperFillManager.fillReport(reportLocation, new HashMap&lt;String, Object&gt;(), beanCollectionDataSource);
  }
  
  
  public void PDF(ActionEvent actionEvent) throws IOException, JRException {
      System.out.println("*****************PDF*********************");
      init();
      JasperExportManager.exportReportToPdfStream(jasperPrint, servletOutputStream);
  }
  </code></pre>
  
  <p>And the XHTML CODE:
      ;</p>
  
  <p>My POM FILE :</p>
  
  <pre><code>&lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
  &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
  &lt;groupId&gt;com.nic&lt;/groupId&gt;
  &lt;artifactId&gt;RFD&lt;/artifactId&gt;
  &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
  &lt;packaging&gt;war&lt;/packaging&gt;
  
  &lt;name&gt;RFD&lt;/name&gt;
  
  &lt;properties&gt;
      &lt;endorsed.dir&gt;${project.build.directory}/endorsed&lt;/endorsed.dir&gt;
      &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
      &lt;netbeans.hint.deploy.server&gt;Tomcat&lt;/netbeans.hint.deploy.server&gt;
  &lt;/properties&gt;
  
  &lt;dependencies&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.eclipse.persistence&lt;/groupId&gt;
          &lt;artifactId&gt;eclipselink&lt;/artifactId&gt;
          &lt;version&gt;2.3.2&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.eclipse.persistence&lt;/groupId&gt;
          &lt;artifactId&gt;javax.persistence&lt;/artifactId&gt;
          &lt;version&gt;2.0.3&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.eclipse.persistence&lt;/groupId&gt;
          &lt;artifactId&gt;org.eclipse.persistence.jpa.modelgen.processor&lt;/artifactId&gt;
          &lt;version&gt;2.3.2&lt;/version&gt;
          &lt;scope&gt;provided&lt;/scope&gt;
      &lt;/dependency&gt;        
      &lt;dependency&gt;
          &lt;groupId&gt;com.sun.faces&lt;/groupId&gt;
          &lt;artifactId&gt;jsf-api&lt;/artifactId&gt;
          &lt;version&gt;2.1.13&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;com.sun.faces&lt;/groupId&gt;
          &lt;artifactId&gt;jsf-impl&lt;/artifactId&gt;
          &lt;version&gt;2.1.13&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;taglibs&lt;/groupId&gt;
          &lt;artifactId&gt;standard&lt;/artifactId&gt;
          &lt;version&gt;1.1.2&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;!-- PrimeFaces --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.primefaces&lt;/groupId&gt;
          &lt;artifactId&gt;primefaces&lt;/artifactId&gt;
          &lt;version&gt;3.4.1&lt;/version&gt;
      &lt;/dependency&gt;  
      &lt;dependency&gt;
          &lt;groupId&gt;org.primefaces.extensions&lt;/groupId&gt;
          &lt;artifactId&gt;all-themes&lt;/artifactId&gt;
          &lt;version&gt;1.0.8&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.primefaces.extensions&lt;/groupId&gt;
          &lt;artifactId&gt;primefaces-extensions&lt;/artifactId&gt;
          &lt;version&gt;0.6.1&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;commons-io&lt;/groupId&gt;
          &lt;artifactId&gt;commons-io&lt;/artifactId&gt;
          &lt;version&gt;1.3.2&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;commons-fileupload&lt;/groupId&gt;
          &lt;artifactId&gt;commons-fileupload&lt;/artifactId&gt;
          &lt;version&gt;1.2.2&lt;/version&gt;
      &lt;/dependency&gt;       
      &lt;dependency&gt;
          &lt;groupId&gt;log4j&lt;/groupId&gt;
          &lt;artifactId&gt;log4j&lt;/artifactId&gt;
          &lt;version&gt;1.2.17&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
          &lt;artifactId&gt;hibernate&lt;/artifactId&gt;
          &lt;version&gt;3.2.6.ga&lt;/version&gt;
          &lt;exclusions&gt;
              &lt;exclusion&gt;
                  &lt;artifactId&gt;antlr&lt;/artifactId&gt;
                  &lt;groupId&gt;antlr&lt;/groupId&gt;
              &lt;/exclusion&gt;
              &lt;exclusion&gt;
                  &lt;artifactId&gt;commons-logging&lt;/artifactId&gt;
                  &lt;groupId&gt;commons-logging&lt;/groupId&gt;
              &lt;/exclusion&gt;
          &lt;/exclusions&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
          &lt;artifactId&gt;hibernate-entitymanager&lt;/artifactId&gt;
          &lt;version&gt;3.3.2.GA&lt;/version&gt;
          &lt;exclusions&gt;
              &lt;exclusion&gt;
                  &lt;artifactId&gt;commons-logging&lt;/artifactId&gt;
                  &lt;groupId&gt;commons-logging&lt;/groupId&gt;
              &lt;/exclusion&gt;
          &lt;/exclusions&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;javax.sql&lt;/groupId&gt;
          &lt;artifactId&gt;jdbc-stdext&lt;/artifactId&gt;
          &lt;version&gt;2.0&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;javax.transaction&lt;/groupId&gt;
          &lt;artifactId&gt;jta&lt;/artifactId&gt;
          &lt;version&gt;1.1&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;mysql&lt;/groupId&gt;
          &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
          &lt;version&gt;5.1.21&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;c3p0&lt;/groupId&gt;
          &lt;artifactId&gt;c3p0&lt;/artifactId&gt;
          &lt;version&gt;0.9.1.2&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.apache.servicemix.bundles&lt;/groupId&gt;
          &lt;artifactId&gt;org.apache.servicemix.bundles.jettison&lt;/artifactId&gt;
          &lt;version&gt;1.0.1_5&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
          &lt;artifactId&gt;hibernate-core&lt;/artifactId&gt;
          &lt;version&gt;4.1.1.Final&lt;/version&gt;
          &lt;type&gt;jar&lt;/type&gt;
          &lt;exclusions&gt;
              &lt;exclusion&gt;
                  &lt;artifactId&gt;antlr&lt;/artifactId&gt;
                  &lt;groupId&gt;antlr&lt;/groupId&gt;
              &lt;/exclusion&gt;
          &lt;/exclusions&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;antlr&lt;/groupId&gt;
          &lt;artifactId&gt;antlr&lt;/artifactId&gt;
          &lt;version&gt;2.7.7&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;junit&lt;/groupId&gt;
          &lt;artifactId&gt;junit&lt;/artifactId&gt;
          &lt;version&gt;4.10&lt;/version&gt;
          &lt;scope&gt;test&lt;/scope&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;commons-beanutils&lt;/groupId&gt;
          &lt;artifactId&gt;commons-beanutils&lt;/artifactId&gt;
          &lt;version&gt;1.8.3&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;javax&lt;/groupId&gt;
          &lt;artifactId&gt;javaee-web-api&lt;/artifactId&gt;
          &lt;version&gt;6.0&lt;/version&gt;
          &lt;scope&gt;provided&lt;/scope&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;javax.mail&lt;/groupId&gt;
          &lt;artifactId&gt;mail&lt;/artifactId&gt;
          &lt;version&gt;1.4.5&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;net.sf.jasperreports&lt;/groupId&gt;
          &lt;artifactId&gt;jasperreports&lt;/artifactId&gt;            
          &lt;version&gt;4.8.0&lt;/version&gt;
          &lt;exclusions&gt;
              &lt;exclusion&gt;
                  &lt;artifactId&gt;commons-beanutils&lt;/artifactId&gt;
                  &lt;groupId&gt;commons-beanutils&lt;/groupId&gt;
              &lt;/exclusion&gt;
          &lt;/exclusions&gt;
      &lt;/dependency&gt;
  &lt;/dependencies&gt;
  
  &lt;build&gt;
  
      &lt;plugins&gt;        
          &lt;plugin&gt;
              &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
              &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
              &lt;version&gt;2.3.2&lt;/version&gt;               
              &lt;configuration&gt;
                  &lt;source&gt;1.6&lt;/source&gt;
                  &lt;target&gt;1.6&lt;/target&gt;
                  &lt;compilerArguments&gt;
                      &lt;endorseddirs&gt;${endorsed.dir}&lt;/endorseddirs&gt;
                  &lt;/compilerArguments&gt;                    
              &lt;/configuration&gt;
          &lt;/plugin&gt;
          &lt;plugin&gt;
              &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
              &lt;artifactId&gt;maven-war-plugin&lt;/artifactId&gt;
              &lt;version&gt;2.1.1&lt;/version&gt;
              &lt;configuration&gt;
                  &lt;failOnMissingWebXml&gt;false&lt;/failOnMissingWebXml&gt;
                  &lt;packagingExcludes&gt;WEB-INF/web.xml&lt;/packagingExcludes&gt;
              &lt;/configuration&gt;
          &lt;/plugin&gt;
          &lt;plugin&gt;
              &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
              &lt;artifactId&gt;maven-dependency-plugin&lt;/artifactId&gt;
              &lt;version&gt;2.1&lt;/version&gt;
              &lt;executions&gt;
                  &lt;execution&gt;
                      &lt;phase&gt;validate&lt;/phase&gt;
                      &lt;goals&gt;
                          &lt;goal&gt;copy&lt;/goal&gt;
                      &lt;/goals&gt;
                      &lt;configuration&gt;
                          &lt;outputDirectory&gt;${endorsed.dir}&lt;/outputDirectory&gt;
                          &lt;silent&gt;true&lt;/silent&gt;
                          &lt;artifactItems&gt;
                              &lt;artifactItem&gt;
                                  &lt;groupId&gt;javax&lt;/groupId&gt;
                                  &lt;artifactId&gt;javaee-endorsed-api&lt;/artifactId&gt;
                                  &lt;version&gt;6.0&lt;/version&gt;
                                  &lt;type&gt;jar&lt;/type&gt;
                              &lt;/artifactItem&gt;
                          &lt;/artifactItems&gt;
                      &lt;/configuration&gt;
                  &lt;/execution&gt;
              &lt;/executions&gt;
          &lt;/plugin&gt;
          &lt;plugin&gt;
              &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;
              &lt;artifactId&gt;jasperreports-maven-plugin&lt;/artifactId&gt;
              &lt;version&gt;1.0-beta-2&lt;/version&gt;
              &lt;configuration&gt;
                  &lt;sourceDirectory&gt;/web/ireport&lt;/sourceDirectory&gt;
                  &lt;outputDirectory&gt;/web/ireport&lt;/outputDirectory&gt;
              &lt;/configuration&gt;
              &lt;executions&gt;
                  &lt;execution&gt;
                      &lt;goals&gt;
                          &lt;goal&gt;compile-reports&lt;/goal&gt;
                      &lt;/goals&gt;
                  &lt;/execution&gt;
              &lt;/executions&gt;
          &lt;/plugin&gt;
      &lt;/plugins&gt;
  &lt;/build&gt;
  &lt;repositories&gt;
      &lt;repository&gt;
          &lt;url&gt;http://download.eclipse.org/rt/eclipselink/maven.repo/&lt;/url&gt;
          &lt;id&gt;eclipselink&lt;/id&gt;
          &lt;layout&gt;default&lt;/layout&gt;
          &lt;name&gt;Repository for library EclipseLink (JPA 2.0)&lt;/name&gt;
      &lt;/repository&gt;
      &lt;repository&gt;
          &lt;url&gt;http://repository.primefaces.org/&lt;/url&gt;
          &lt;id&gt;primefaces&lt;/id&gt;
          &lt;layout&gt;default&lt;/layout&gt;
          &lt;name&gt;Repository for library PrimeFaces 3.2&lt;/name&gt;
      &lt;/repository&gt;                
  &lt;/repositories&gt;
  </code></pre>
  
  <p></p>
  
  <p>Please Help</p>
  
  <p>I have not used the Function getOutputStream() anywhere else in my project.</p>