<%@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="net.sf.json.JSONObject"%> <%@ page contentType="text/html; charset=UTF-8"%> <%@ include file="/common/taglibs.jsp"%> <%@ include file="/common/includeExtJsAndCss.jsp"%> <%-- 报表显示的div --%>
<% StringBuffer sbuffer = new StringBuffer(); int pageIndex = 0; int lastPageIndex = 0; String timeStamp = request.getParameter("currentTime"); String isPrint = request.getParameter("isPrint"); String hidePrintBtn = request.getParameter("hidePrintBtn"); request.setAttribute("isPrint",isPrint); request.setAttribute("hidePrintBtn",hidePrintBtn); String reportName = ""; //报表的名称 //是否启用报表导出html或pdf功能,1显示报表导出pdf图标 2显示报表导出html图标 3都显示 JSONObject sstsConfig = CssdUtils.getWebConfigInfo(); String reportExportExtraFormat = sstsConfig.optString("reportExportExtraFormats","0"); try{ if(timeStamp == null ){ timeStamp = ""; } JasperPrint jasperPrint = (JasperPrint)session.getAttribute("JasperPrint"+timeStamp); 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); 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; } 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("空页面!"); } %>
  <%=sbuffer.toString()%>  
<%-- 分页导航栏 --%> <% if("true".equals(isPrint)){ %>
<% }else{ %>
<% } %>
<% if("1".equals(reportExportExtraFormat) || "3".equals(reportExportExtraFormat)){ %> <% } %> <% if("2".equals(reportExportExtraFormat) || "3".equals(reportExportExtraFormat)){ %> <% } %> <% if (!reportName.equals("apparatusInfusionisType") && !"true".equals(hidePrintBtn)) { %> <%-- --%> <% } %> 第<%=pageIndex+1%>页,共<%=lastPageIndex+1%>页 <% String currentTimeStr = (String)request.getAttribute("currentTime"); String reportUrl = "/jasperRtp/jasperreportsView.jsp?currentTime=" + currentTimeStr; if (pageIndex > 0) { %> <% } else { %> <% } if (pageIndex < lastPageIndex) { %> <% } else { %> <% } %>