title: java.lang.IllegalStateException: getOutputStream() has already been called for this response
body: <p>Here is my code for which I am getting the following exception</p>
  <pre><code>HTTP Status 500 - Unable to show problem report: java.lang.IllegalStateException: getOutputStream() has already been called for this response
  </code></pre>
  <p><strong>The code:</strong></p>
  <pre><code>WorkbookSettings wbSettings = new WorkbookSettings();    
  OutputStream outStream = null;
              
  try
  {               
    wbSettings.setLocale(new Locale(&quot;en&quot;, &quot;EN&quot;));             
    response.setContentType(&quot;application/vnd.ms-excel&quot;);                  
    outStream= response.getOutputStream();                
    response.setHeader(&quot;Content-Disposition&quot;, &quot;attachment; filename=/timesheet.xls&quot;);             
    WritableWorkbook workbook = Workbook.createWorkbook(outStream, wbSettings);              
    workbook.createSheet(&quot;Report&quot;, 0);               
    WritableSheet excelSheet = workbook.getSheet(0);              
    service.createLabel(excelSheet);              
    service.createContent(excelSheet);                    
    workbook.write();             
    workbook.close();             
    outStream.flush();               
    outStream.close();                
  }               
  catch(Exception e)
  {
  }           
  finally
  {               
    //outStream.close();      
  }   
  return &quot;generateReport&quot;;
  </code></pre>
  <p><strong>My <code>Struts.xml</code> looks like this:</strong></p>
  <pre class="lang-xml prettyprint-override"><code>&lt;result type=&quot;stream&quot; name=&quot;generateReport&quot;&gt;                   
   &lt;param name=&quot;contentType&quot;&gt;&quot;application/vnd.ms-excel&quot;&lt;/param&gt;                  
   &lt;param name=&quot;inputName&quot;&gt;excelstream&lt;/param&gt;                  
   &lt;param name=&quot;contentDisposition&quot;&gt;contentDisposition&lt;/param&gt;                   
   &lt;param name=&quot;bufferSize&quot;&gt;1024&lt;/param&gt;              
  &lt;/result&gt;
  </code></pre>
  <p>In JSP, I am just giving a button which gives me <code>open, save</code> dialog box.
  After clicking that button I am getting the exception.</p>
  <p>How to avoid this?</p>