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 xmlxdm =(string) request.getparameter("xmlxdm");
string planyear =(string) request.getparameter("planyear");
parameters = new hashmap();
parameters.put("deptid", deptid);
parameters.put("xmlxdm", xmlxdm);
parameters.put("planyear", planyear);
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();
}
%>
import="java.io.*,
net.sf.jerreports.engine.*,
net.sf.jasperreports.engine.util.*,
java.util.*,java.sql.*,
net.sf.jasperreports.engine.export.*"%>
//参数获取
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());
//向报表传递参数
mapparameters.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();
}
%>