%@ page contentType="text/html; charset=UTF-8"%>
<%@page import="java.net.URLEncoder"%>
<%@page import="net.sf.jasperreports.engine.JRException"%>
<%@page import="net.sf.jasperreports.j2ee.servlets.ImageServlet"%>
<%@page import="java.io.IOException"%>
<%@page import="java.io.OutputStream"%>
<%@page import="net.sf.jasperreports.engine.JRExporterParameter"%>
<%@page import="net.sf.jasperreports.engine.JasperPrint"%>
<%@page import="net.sf.jasperreports.engine.JRExporter"%>
<%@page import="net.sf.jasperreports.engine.export.JRHtmlExporter"%>
<%@page import="net.sf.jasperreports.engine.export.JRHtmlExporterParameter"%>
<%
Object obj = session.getAttribute(ImageServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE);
JasperPrint jasperPrint = null;
if(obj instanceof JasperPrint){
jasperPrint = (JasperPrint)obj;
}
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){
}
JRHtmlExporter htmlExporter = new JRHtmlExporter();
htmlExporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
htmlExporter.setParameter(JRExporterParameter.OUTPUT_STREAM,outputStream);
htmlExporter.setParameter(JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN,Boolean.FALSE);
htmlExporter.setParameter(JRHtmlExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS,Boolean.TRUE);
htmlExporter.setParameter(JRHtmlExporterParameter.IGNORE_PAGE_MARGINS,Boolean.TRUE);
//htmlExporter.setParameter(JRHtmlExporterParameter.IS_WHITE_PAGE_BACKGROUND,Boolean.TRUE);
try {
htmlExporter.exportReport();
outputStream.close();
out.clear();
out = pageContext.pushBody();
} catch (JRException e) {
e.printStackTrace();
}
%>