欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

JSP中调用Ireport报表文件并展示效果源码

程序员文章站 2023-12-25 21:19:45
pageencoding="utf-8"%> import="java.io.*, net.sf.jerreports.engine.*, net.sf.jasperreports.engine...
pageencoding="utf-8"%>
import="java.io.*,
net.sf.jerreports.engine.*,
net.sf.jasperreports.engine.util.*,
java.util.*,java.sql.*,
net.sf.jasperreports.engine.export.*"%>




insert title here



//参数获取

string deptid =(string) request.getparameter("deptid");
string xmlxdm =(string) request.getparameter("xmlxdm");
string planyear =(string) request.getparameter("planyear");

//调用报表模版

file reportfile = new file(application.getrealpath("/report/roadplanexportexcel.jasper"));

jasperreport jasperreport = (jasperreport) jrloader.loadobject(reportfile.getpath());

//向报表传递参数

map parameters = new hashmap();
parameters.put("deptid", deptid);
parameters.put("xmlxdm", xmlxdm);
parameters.put("planyear", planyear);

parameters.put("title", planyear+"xxxxxx项目表--");

//jdbc连接数据源

connection conn =null;
try{
class.forname("oracle.jdbc.driver.oracledriver");
conn = drivermanager.getconnection(
"jdbc:oracle:thin:@127.0.0.1:1521:xxx", "xxxx", "xxxx");
jasperprint jasperprint = jasperfillmanager.fillreport(
jasperreport, parameters, conn);
jrhtmlexporter exporter = new jrhtmlexporter();

exporter.setparameter(jrexporterparameter.jasper_print, jasperprint);
exporter.setparameter(jrexporterparameter.output_writer, out);

exporter.setparameter(jrhtmlexporterparameter.is_using_images_to_align, boolean.false);
exporter.exportreport();
out.flush();
conn.close();
}catch(exception e){
if (null != conn) conn.close();
e.printstacktrace();
}finally{
if (null != conn) conn.close();
}
%>

上一篇:

下一篇: