jsp调用ireport进行客户端打印

本文介绍了一个使用JSP和Java技术生成报表的具体实现案例。通过内嵌的Java Applet组件,客户端可以在浏览器中预览并打印由服务器端动态生成的报表。此方案依赖于客户端安装了JDK,并且服务器端部署了必要的jar包。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

前提:客户端需要安装jdk,服务段需要有相关的jar包,itext包等。。。

jsp:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<head>
<title>打印</title>
<link rel="stylesheet" href="/gbcpgl/gbcpgl_web/abc/public.css" type="text/css"/> 
</head>
<body scroll="no" style="overflow: hidden;">
<object 
    classid = "clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" 
    codebase = "http://java.sun.com/update/1.6.0/jinstall-6u13-windows-i586.cab#Version=6,0,0,3" 
    WIDTH = "100%" HEIGHT = "100%" >
    <PARAM NAME = CODE VALUE = "EmbeddedViewerApplet.class" >
    <PARAM NAME = CODEBASE VALUE = "../../applets" >
    <PARAM NAME = ARCHIVE VALUE = "jasperreports-3.5.3-applet.jar,commons-logging-1.0.2.jar,commons-collections-2.1.jar" >
    <param name = "type" value = "application/x-java-applet;version=1.6">
    <param name = "scriptable" value = "false">
<!--           请求的servlet路径         -->
    <PARAM NAME = "REPORT_URL" VALUE ="someServlet?someParam">
 
</object>
</body>
</html>
 
servlet核心代码:
String jasperName = session.getServletContext().getRealPath("/report_print/office_template") + File.separator + "jywwdjb_bg2.jasper";
try {
DriverManagerDataSource ds = 。。。;
JasperReport jasperReport = (JasperReport) JRLoader.loadObject(jasperName);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport,paramMap,ds.getConnection());
  if (jasperPrint != null)
  {
  response.setContentType("application/octet-stream");
  ServletOutputStream ouputStream = response.getOutputStream();
  ObjectOutputStream oos = new ObjectOutputStream(ouputStream);
  oos.writeObject(jasperPrint);
  oos.flush();
  oos.close();
 
  ouputStream.flush();
  ouputStream.close();
  }
} catch (JRException e) {
e.printStackTrace();
}catch (Exception e) {
e.printStackTrace();
log.error(e.getLocalizedMessage());
}

转载于:https://www.cnblogs.com/wangdonghua/p/3320794.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值