Index: ssts-web/src/main/webapp/jasperRtp/jasperreportsView.jsp =================================================================== diff -u -r35593 -r35613 --- ssts-web/src/main/webapp/jasperRtp/jasperreportsView.jsp (.../jasperreportsView.jsp) (revision 35593) +++ ssts-web/src/main/webapp/jasperRtp/jasperreportsView.jsp (.../jasperreportsView.jsp) (revision 35613) @@ -1,15 +1,14 @@ -<%@page import="java.io.ByteArrayOutputStream"%> <%@page import="java.util.Date"%> +<%@page import="java.util.HashMap"%> +<%@page import="net.sf.jasperreports.engine.export.JRXhtmlExporter"%> +<%@page import="net.sf.jasperreports.engine.export.JRHtmlExporterParameter"%> +<%@page import="net.sf.jasperreports.j2ee.servlets.ImageServlet"%> +<%@page import="net.sf.jasperreports.engine.JRExporterParameter"%> +<%@page import="net.sf.jasperreports.engine.export.JRHtmlExporter"%> <%@page import="net.sf.jasperreports.engine.JasperPrint"%> <%@page import="com.forgon.disinfectsystem.common.CssdUtils"%> -<%@page import="com.forgon.tools.util.FileUtils"%> <%@page import="net.sf.json.JSONObject"%> -<%@page import="net.sf.jasperreports.export.SimpleExporterInput"%> -<%@page import="net.sf.jasperreports.export.SimpleHtmlExporterOutput"%> -<%@page import="net.sf.jasperreports.export.SimpleHtmlReportConfiguration"%> -<%@page import="net.sf.jasperreports.engine.export.HtmlExporter"%> - <%@ page contentType="text/html; charset=UTF-8"%> <%@ include file="/common/taglibs.jsp"%> <%@ include file="/common/includeExtJsAndCss.jsp"%> @@ -111,7 +110,7 @@ <%-- 报表显示的div --%>
<% - String tableStr = ""; + StringBuffer sbuffer = new StringBuffer(); int pageIndex = 0; int lastPageIndex = 0; String timeStamp = request.getParameter("currentTime"); @@ -124,47 +123,51 @@ JSONObject sstsConfig = CssdUtils.getWebConfigInfo(); String reportExportExtraFormat = sstsConfig.optString("reportExportExtraFormats","0"); try{ - if(timeStamp == null){ + if(timeStamp == null ){ timeStamp = ""; } JasperPrint jasperPrint = (JasperPrint)session.getAttribute("JasperPrint"+timeStamp); - if(jasperPrint != null && jasperPrint.getPages() != null && jasperPrint.getPages().size() > 0){ + JasperPrint jasperPrintForPrint = (JasperPrint)session.getAttribute("jasperPrintForPrint"+timeStamp); + if(jasperPrint != null){ reportName = jasperPrint.getName(); + session.setAttribute(ImageServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE,jasperPrintForPrint); String currentTime = new Date().toString(); request.setAttribute("currentTime",currentTime); session.setAttribute("JasperPrint"+currentTime,jasperPrint); - JasperPrint jasperPrintForPrint = (JasperPrint)session.getAttribute("jasperPrintForPrint"+timeStamp); session.setAttribute("jasperPrintForPrint"+currentTime,jasperPrintForPrint); + JRXhtmlExporter exporter = new JRXhtmlExporter(); + if (jasperPrint.getPages() != null){ lastPageIndex = jasperPrint.getPages().size() - 1; } String pageStr = request.getParameter("pageIndex"); + try{ if( pageStr != null) pageIndex = Integer.parseInt(pageStr); session.setAttribute("pageIndex", pageIndex); }catch(Exception e){ } - + if (pageIndex < 0){ pageIndex = 0; } if (pageIndex > lastPageIndex){ pageIndex = lastPageIndex; } - HtmlExporter exporterHTML = new HtmlExporter(); - ByteArrayOutputStream htmlStream = new ByteArrayOutputStream(); - SimpleHtmlReportConfiguration reportExportConfiguration = new SimpleHtmlReportConfiguration(); - reportExportConfiguration.setWhitePageBackground(false); - reportExportConfiguration.setPageIndex(pageIndex); - reportExportConfiguration.setRemoveEmptySpaceBetweenRows(true); - exporterHTML.setConfiguration(reportExportConfiguration); - exporterHTML.setExporterInput(new SimpleExporterInput(jasperPrint)); - exporterHTML.setExporterOutput(new SimpleHtmlExporterOutput(htmlStream)); - exporterHTML.exportReport(); - tableStr = htmlStream.toString("UTF-8"); + + exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); + exporter.setParameter(JRExporterParameter.OUTPUT_STRING_BUFFER, sbuffer); + //加time参数解决 IFrame中的图片存在缓存机制 + exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, request.getContextPath()+"/servlets/image?time="+currentTime+"&image="); + exporter.setParameter(JRExporterParameter.PAGE_INDEX, new Integer(pageIndex)); //输出第几页 + //exporter.setParameter(JRHtmlExporterParameter.HTML_HEADER, ""); + exporter.setParameter(JRHtmlExporterParameter.BETWEEN_PAGES_HTML, ""); + //exporter.setParameter(JRHtmlExporterParameter.HTML_FOOTER, ""); + + exporter.exportReport(); } }catch(Exception e){ System.out.print("空页面!"); @@ -174,7 +177,7 @@ - +
 <%=tableStr%><%=sbuffer.toString()%>