※问题类别:JSP,jasperreports-4.1.3.jar
※系统环境:JDK 1.6,apache-tomcat-8.5.75
※状况概述:
我想把Ireport产出的PDF在网页上显示
已经产生jasper档,在Ireport中有预览成功
参考网络上一些JSP档案的范例
一开始是JAR好像一直无法引用进来
查了资料好像环境参数要指定classpath
像补充图片那样设定,不太确定是不是对的,但compiler好像过了
再来就卡在JasperFillManager.fillReport这一行
我试了好多方式,再麻烦大神看看我哪里错了
本来也有想说用Eclipse
但对Java不太了解,也是遇到一些困难
如果有其他建议我也可以再试看看
谢谢!
※程式码:
<%@page language="java" contentType="application/pdf; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@page import ="net.sf.jasperreports.engine.*"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Connection"%>
<%@page import="java.util.HashMap"%>
<%@page import="java.util.Map"%>
<%@page import="java.io.File"%>
<%@page import="java.io.FileInputStream"%>
<%@page import="java.io.InputStream"%>
<%@page import="net.sf.jasperreports.engine.util.*" %>
<%@page import="net.sf.jasperreports.engine.export.*" %>
<%@page import="net.sf.jasperreports.j2ee.servlets.*" %>
<%@page import="net.sf.jasperreports.engine.data.JRBeanCollectionDataSource"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="application/pdf;
charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%
response.reset();
File reportFile = new File("C:/apache-tomcat-8.5.75/webapps/ROOT/HR/report
2.
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Connection conn = DriverManager.getConnection("");
Map parameters = new HashMap();
out.println("reportFile.getPath:"+reportFile.getPath()+"<br/>");
out.println("conn:"+conn);
JasperPrint jasperPrint = JasperFillManager.fillReport(reportFile.getPath(
),
%>
</body>
</html>
※错误讯息:
https://imgur.com/jJh1yQy
※补充说明:
classpth设定
https://imgur.com/5dpCTHe
jasper放的位置
https://imgur.com/f37b3Xa
传进去fillReport()的reportFile.getPath跟conn 用out.println看实际的值
https://imgur.com/tJeiuez