天天看点

IReport+JasperReport+Applet报表打印

实现思路:

  1. 【准备】使用IReport设计并编译报表模版。
  2. 【服务端】使用JSP完成报表内容填充并获得打印对象。
  3. 【客户端】使用Applet完成报表打印过程。

这种实现方式需要客户端安装JRE,及打印机驱动。

下面逐步分解:

1.【准备】使用IReport设计并编译报表模版。

IReport的安装过程略……。

创建1个简单的报表并编译:

IReport+JasperReport+Applet报表打印

2.【服务端】使用JSP完成报表内容填充并获得打印对象。

    a.在工程中引入依赖的JAR包,根据报表的组件可能有变化,此处只根据样例报表,引用少数几个。

IReport+JasperReport+Applet报表打印

    b.编写JSP页面内容:

IReport+JasperReport+Applet报表打印

    JSP页面设计思路:

    客户端提交参数清单包含报表资源和参数清单两部分,报表资源通过file参数传入,参数清单即为提交的剩余参数内容,由JSP代码整理并转交给报表处理。

    JSP生成打印对象JasperPrint,并返回。

3.【客户端】使用Applet完成报表打印过程。

    a.编写Applet类

IReport+JasperReport+Applet报表打印

    Applet设计思路:

    提交HTTP请求,将报表的生产过程交给服务端完成,自身只接受返回的JasperPrint对象,并完成打印过程。

    b.编写浏览器处理代码

IReport+JasperReport+Applet报表打印

    c.完成客户端配置

    客户端配置根据JRE的版本确定,一般包含2各部分:%JRE_HOME%/lib/security/java.policy和“配置Java”安全站点设定。

IReport+JasperReport+Applet报表打印
IReport+JasperReport+Applet报表打印

4.运行效果

    页面运行效果:

IReport+JasperReport+Applet报表打印
IReport+JasperReport+Applet报表打印

    直接点击按钮即可生成报表。

IReport+JasperReport+Applet报表打印

    保存后打开效果:

IReport+JasperReport+Applet报表打印

    添加报表参数:&Code=Code1

IReport+JasperReport+Applet报表打印

    点击按钮生成报表

IReport+JasperReport+Applet报表打印

    保存后打开效果:

IReport+JasperReport+Applet报表打印

转载于:https://blog.51cto.com/zglei/1870694