代码如下:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page language="java" import="java.sql.*"%>
<%@ page language="java" import="java.io.*"%>
<%@ page language="java" import="net.sf.jasperreports.engine.*"%>
<%@ page language="java" import="util.*"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>自编译报表测试</title>
</head>
<body>
<%
String path1 = request.getContextPath();
Connection con = DBUtils.getConnection();
File reportFile = new File(this.getServletContext().getRealPath(
"/report/yc/yc.jasper"));
System.out.println(reportFile);
Map parameters = new HashMap();
try {
JasperRunManager.runReportToHtmlFile(reportFile.getPath(),
parameters, con);
response.sendRedirect(path1 + "/report/yc/yc.html");
} catch (Exception e) {
System.out.print(e);
} finally {
try {
con.close();
} catch (Exception ex) {
System.out.print(ex);
}
}
%>
</body>
</html>
路径如下:
报错截图如下:
恳请高手解决。
决在安装了jdk1.6.0_26,又安装JDK1.8.2后导致iReport无法启动加载的问题
你这边是重定向,完整路径应该是: basePath + "report/yc/yc.html"
你应该是重定向这边找不到文件路径,具体路径应该是: basePath + "report/yc/yc.html"
二楼,三楼的,我试过了,还是不行啊。
一楼,我的JDK是1.6,其它没装。
不过还是感谢两位
顶起来,要不就沉贴了。。。。。。。。。。。。。。。。。。
File reportFile = new File(this.getServletContext().getRealPath("/reoprt/yc/yc.jasper"));-----------//你这条代码里的路径打错了,report
楼上的,谢谢!果然是低级错误!
但是我运行后,还是报错,报错如下:
java.lang.ClassCastException: cannot assign instance of net.sf.jasperreports.engine.base.JRBaseStaticText to field net.sf.jasperreports.engine.base.JRBaseParagraph.paragraphContainer of type net.sf.jasperreports.engine.JRParagraphContainer in instance of net.sf.jasperreports.engine.base.JRBaseParagraph
还请继续帮忙,谢谢!