jsp页面中如何调用ireport生成的.jasper文件?能给一个jsp页面中的代码么 10
1个回答
展开全部
你参考一下下边的代码
<%@ page contentType="application/pdf;charset=GB2312"%>
<%@ page import="dori.jasper.engine.*" %>
<%@ page import="dori.jasper.engine.util.*" %>
<%@ page import="dori.jasper.engine.export.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.io.*" %>
<%@ page import="java.sql.*" %>
<%
//报表编译之后生成的.jasper 文件的存放位置
File reportFile = new File(application.getRealPath("/report/test_report_1.jasper"));
//这个是用来联接我的SQL Server 的JDBC URL
String url ="jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=film";
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
Map parameters = new HashMap();
parameters.put("name", "p");
System.out.println("---------conn-------------");
//连接到数据库
Connection conn =DriverManager.getConnection(url,"sa", "");
System.out.println("---------Jasper begin-------------");
//在控制台显示一下报表文件的物理路径
System.out.println(reportFile.getPath());
byte[] bytes=JasperRunManager.runReportToPdf(reportFile.getPath(),parameters,conn);
System.out.println("---------Jasper end-------------");
response.setContentType("application/pdf");
response.setContentLength(bytes.length);
ServletOutputStream ouputStream = response.getOutputStream();
ouputStream.write(bytes, 0, bytes.length);
ouputStream.flush();
ouputStream.close();
如果不行的话,我在想想别的办法吧!
<%@ page contentType="application/pdf;charset=GB2312"%>
<%@ page import="dori.jasper.engine.*" %>
<%@ page import="dori.jasper.engine.util.*" %>
<%@ page import="dori.jasper.engine.export.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.io.*" %>
<%@ page import="java.sql.*" %>
<%
//报表编译之后生成的.jasper 文件的存放位置
File reportFile = new File(application.getRealPath("/report/test_report_1.jasper"));
//这个是用来联接我的SQL Server 的JDBC URL
String url ="jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=film";
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
Map parameters = new HashMap();
parameters.put("name", "p");
System.out.println("---------conn-------------");
//连接到数据库
Connection conn =DriverManager.getConnection(url,"sa", "");
System.out.println("---------Jasper begin-------------");
//在控制台显示一下报表文件的物理路径
System.out.println(reportFile.getPath());
byte[] bytes=JasperRunManager.runReportToPdf(reportFile.getPath(),parameters,conn);
System.out.println("---------Jasper end-------------");
response.setContentType("application/pdf");
response.setContentLength(bytes.length);
ServletOutputStream ouputStream = response.getOutputStream();
ouputStream.write(bytes, 0, bytes.length);
ouputStream.flush();
ouputStream.close();
如果不行的话,我在想想别的办法吧!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询