<%@page import="net.sf.jasperreports.export.SimpleHtmlReportConfiguration"%> <%@page import="net.sf.jasperreports.engine.export.HtmlExporter"%> <%@page import="net.sf.jasperreports.export.SimpleExporterInput"%> <%@page import="net.sf.jasperreports.export.SimpleHtmlExporterOutput"%> <%@ page contentType="text/html; charset=UTF-8"%> <%@page import="java.net.URLEncoder"%> <%@page import="java.io.IOException"%> <%@page import="java.io.OutputStream"%> <%@page import="net.sf.jasperreports.engine.JasperPrint"%> <% JasperPrint jasperPrint = (JasperPrint)session.getAttribute("jasperPrintForPrint"); OutputStream outputStream = null; try { response.setContentType("text/html"); response.setCharacterEncoding("UTF-8"); response.setHeader("Content-Disposition", "attachment;filename="+URLEncoder.encode(session.getAttribute("fileName")+".html", "UTF-8")); outputStream = response.getOutputStream(); }catch (IOException e) { //e.printStackTrace(); }catch(IllegalStateException e){ } try { HtmlExporter exporterHTML = new HtmlExporter(); exporterHTML.setExporterInput(new SimpleExporterInput(jasperPrint)); SimpleHtmlReportConfiguration reportExportConfiguration = new SimpleHtmlReportConfiguration(); SimpleHtmlExporterOutput exporterOutput = new SimpleHtmlExporterOutput(outputStream); reportExportConfiguration.setWhitePageBackground(Boolean.TRUE); reportExportConfiguration.setRemoveEmptySpaceBetweenRows(Boolean.TRUE); reportExportConfiguration.setIgnorePageMargins(Boolean.TRUE); exporterHTML.setConfiguration(reportExportConfiguration); exporterHTML.setExporterOutput(exporterOutput); exporterHTML.exportReport(); outputStream.close(); out.clear(); out = pageContext.pushBody(); } catch (Exception e) { e.printStackTrace(); } %>