title: Export JasperReports in HTML format
body: <p>The code below gets a <code>byte[]</code> result, which works for PDF and XLSX. For HTML, an exception is raised.</p>
  
  <pre><code>    JasperPrint jasperPrint = JasperFillManager.fillReport(report,
              params, dataSource != null ? new JRMapArrayDataSource(
                      dataSource) : new JREmptyDataSource());
  
      ByteArrayOutputStream out = new ByteArrayOutputStream();
      @SuppressWarnings("rawtypes")
      Exporter exporter;
      switch (format) {
      case PDF:
          exporter = new JRPdfExporter();
          break;
      case XLSX:
          exporter = new JRXlsxExporter();
          break;
      case HTML:
          exporter = new HtmlExporter();
          break;
      default:
          throw new ReportException("Unknown export format");
      }
      exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(out));
      exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
      exporter.exportReport();
      return out.toByteArray();
  </code></pre>
  
  <p>The exception for HTML is at  <code>exporter.exportReport();</code> line which says</p>
  
  <pre><code>java.lang.ClassCastException: 
  
  net.sf.jasperreports.export.SimpleOutputStreamExporterOutput cannot be cast to net.sf.jasperreports.export.HtmlExporterOutput
  at net.sf.jasperreports.engine.export.HtmlExporter.exportReport(HtmlExporter.java:232)
  </code></pre>
  
  <p>The error is the same for v6.0 and v5.6. This used to work in v5.0 (some of the classes were deprecated in v5.6).</p>
  
  <p>How do you export a report in various formats, including HTML?</p>