Jasper客户端打印,通过demo中webapp的applet来实现

来源:互联网 发布:主力为什么要洗盘 知乎 编辑:程序博客网 时间:2024/05/17 04:15
1.系统框架:webwork+ibtatis+spring2.webwork已经有集成jasper===========================================仅需如下配置xwork.xml /WEB-INF/pages/application/netprint/emsmail/emsmail.jasper emsmailList PDF 以上这种方式仅能导出相应的数据如生成pdf,xls等.为了能够打印,则需重写该方式,配置如下: 将上面原来导出的 type="jasper"修改为 type="exjasper",就会调会XXX.JasperReportsResult这个类这个类修改原JasperReportsResult,我拷备的是struct2中的这个类,同时修改以下内容.A.JasperReportsResult extends WebWorkResultSupport implements JasperReportConstantsB.去除writeReport(HttpServletResponse response, byte[] output) exportReportToBytes(JasperPrint jasperPrint, JRExporter exporter)C // Fill the report and produce a print object try { JasperReport jasperReport = (JasperReport) JRLoader.loadObject(systemId); jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, stackDataSource); //1JasperPrintManager.printReport(jasperPrint, true);//2008-08-25 直接打印,不用预览PDF直接打印 true为弹出打印机选择.false为直接打印.如果采用该方式,只能服务端打印. } catch (JRException e) { LOG.error("Error building report for uri " + systemId, e); throw new ServletException(e.getMessage(), e); }//2采用以下方案,目的是将 jasperPrint 作为一个对象写入数据流,客户端通过applet取得response.setContentType("application/octet-stream"); ServletOutputStream ouputStream = response.getOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(ouputStream); oos.writeObject(jasperPrint);//将JasperPrint对象写入对象输出流中 oos.flush(); oos.close(); ouputStream.flush(); ouputStream.close();=============================================3.applet的实现=============================================调用applet的jsp页面,同时传入参数REPORT_URL.<%@page language="java" isErrorPage="true" pageEncoding="GB2312" contentType="text/html;charset=gb2312" %><%@include file="/common/taglibs.jsp"%>" />A.配置ant,编译demo中的webapp在cmd中输入set path=%path%;D:/eclipse/eclipse/plugins/org.apache.ant_1.7.0.v200706080842/bin(这个的设置根据eclipse中已经有ant了,通过anthome查看该路径,使cmd识别ant命令)然后进入webapp中,在此文件夹下有一个build.xml文件,ant会根据该文件进行编辑运行.B,在编译运行之后,生成applets下会生成相应的class与所需的包,然后还需增加log4j.jar包就OK了.拷备到你的工作目录下,应该就可以运行了.C 说明,如果单独运行以上的测试文件,只需要applets与该html文件在同一目录下就可以否则会发生找不到PrinterApplet.class的异常.如果打开的该 html打开是有路径的如http://localhost/nettest/mytest.html,则,需要将applets整个复制到相应的路径下如nettest/applets下,这个才可以正常运行.============================================================4.这个框架不完善的地方是A,applet加载很慢,而且客户必须安装jre.B.打印不能直接运行,因为applet运行很慢,如果在applet的构造方法时调用打印程序,会产生REPORT_URL无法正常读取的异常.
原创粉丝点击