jsp
function equipTag(obj) {
url="reportContent.jsp?tagType=BMK&EquipId=1";
pass = escape(url);
window.open("report/report.jsp?url="+pass+"&flag=true","","height=100,width=500,status=yes,toolbar=yes,menubar=no,location=no");
}
_____________________________________________________________________________________________________________
report/report.jsp:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<%@ page
language="java"
contentType="text/html; charset=GBK"
pageEncoding="GBK"
%>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<META http-equiv="Content-Style-Type" content="text/css">
<link href="/traffic/jsp/css/css.css" rel="stylesheet" type="text/css">
<title>report.jsp</title>
<SCRIPT language="JavaScript">
function openApp(url,isView)
{
document.write('<APPLET ID="JrPrt" CODE = "report.applet.JRPrinterApplet.class" CODEBASE = "." ARCHIVE = "rptApplet.jar;jasperreports-2.0.2-javaflow.jar" WIDTH = "0" HEIGHT = "0">');
document.write('<PARAM NAME = "type" VALUE="application/x-java-applet;version=1.6">');
document.write('<PARAM NAME = "scriptable" VALUE="false">');
document.write('<PARAM NAME = "REPORT_URL" VALUE ="'+url+'">');
document.write('<PARAM NAME = "IS_VIEW" VALUE ="'+isView+'">');
document.write('</APPLET>');
}
</script>
</head>
<body>
<input type="hidden" name="url" value="<%=request.getParameter("url")%>">
<input type="hidden" name="flag" value="<%=request.getParameter("flag")%>">
<script>
openApp(document.all.url.value,document.all.flag.value);
</script>
<font color="red">正在读取数据,请稍候!</font>
<%//out.print(request.getParameter("url"));%>
</body>
</html>
____________________________________________________________________________________
report/reportContent.jsp
<%@page contentType="text/html;charset=GBK"%>
<%@ page import="java.sql.*"%>
<%@ page import="java.io.File"%>
<%@ page import="java.io.ObjectOutputStream"%>
<%@ page import="java.util.Map"%>
<%@ page import="java.util.HashMap"%>
<%@ page import="javax.servlet.ServletOutputStream"%>
<%@ page import="net.sf.jasperreports.engine.JasperFillManager"%>
<%@ page import="net.sf.jasperreports.engine.JasperPrint"%>
<%@ page import="net.sf.jasperreports.engine.JRException"%>
<%@ page import="com.ck.web.framework.WebContext"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
</head>
<body>
<%
String tagType = request.getParameter("tagType");
WebContext ctx = WebContext.getInstance();
Connection conn = null;
conn = ctx.getConnection(request.getSession());
try {
HashMap parameters = new HashMap();
JasperPrint jasperPrint = null;
response.setContentType("application/octet-stream");
ServletOutputStream ouputStream = response.getOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(ouputStream);
parameters.put("REPORT_PATH", "report");
File f = null;
//领用/借用
//if (request.getParameter("dispatch").equals("applayUsr"))
{
if(tagType.equals("BMK")) {
f = new File(request.getRealPath("/report/equip_tag_bmk.jasper"));
} else if(tagType.equals("GLK")) {
f = new File(request.getRealPath("/report/equip_tag_glk.jasper"));
} else {
f = new File(request.getRealPath("/report/equip_tag.jasper"));
}
parameters.put("EquipId", request.getParameter("EquipId"));
}
/** fill report* */
jasperPrint = JasperFillManager.fillReport(f.getPath(), parameters, conn);
if (jasperPrint != null) {
oos.writeObject(jasperPrint);//将JasperPrint对象写入对象输出流中
oos.flush();
oos.close();
} else {
throw new JRException("报表程序出错");
}
} catch (Exception E) {
System.out.println(E.getMessage());
} finally {
out.clear();
out = pageContext.pushBody();
conn.close();
}
%>
</body>
</html>