设为首页 加入收藏

TOP

jsp调用ireport进行客户端打印
2019-05-12 14:33:05 】 浏览:100
Tags:jsp 调用 ireport 进行 客户端 打印
前提:客户端需要安装jdk,服务段需要有相关的jar包,itext包等。。。

jsp:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<head>
<title>打印</title>
</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 ="someServletsomeParam">
</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());
}

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇看了《spring技术内幕》简单的图.. 下一篇scala学习笔记1(表达式)

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目