1
回答
Myeclipse环境下JSP调用JasperReports报错 demo
华为云实践训练营,热门技术免费实践!>>>   

初学JasperReports,各位大神是否有Myeclipse环境下调用JasperReports 生成报表的demo project?最好带数据库脚本,多谢 。我已经用ireport做好了*.japser文件,在JSP页面中直接调用Jasperreports总报错,错误如下:

org.apache.jasper.JasperException: Unable to compile class for JSP: 

An error occurred at line: 23 in the jsp file: /report.jsp
The method runReportToHtmlFile(String, String, Map<String,Object>, Connection) in the type JasperRunManager is not applicable for the arguments (File, String, Map, Connection)
20: 	try {
21: 		//执行报表程序 
22: 		System.out.println("---------conn-------------");
23: 		JasperRunManager.runReportToHtmlFile(reportFile,ctxpath,parameters,conn);
24: 		System.out.println("---------conn-------------");
25: 		response.sendRedirect(ctxpath + "/myreport.html");
26: 


Stacktrace:
	org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
	org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
	org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:439)
	org.apache.jasper.compiler.Compiler.compile(Compiler.java:349)
	org.apache.jasper.compiler.Compiler.compile(Compiler.java:327)
	org.apache.jasper.compiler.Compiler.compile(Compiler.java:314)
	org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:589)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

note The full stack trace of the root cause is available in the Apache Tomcat/6.0.26 logs.

我的JSP页面如下,<%@ page contentType="text/html;charset=GB2312"%>

<%@ page import="net.sf.jasperreports.engine.JasperRunManager"%>

<%@ page import="java.util.*"%>

<%@ page import="java.io.*"%>

<%@ page import="java.sql.*"%>

<%

String ctxpath = request.getContextPath();

//创建数据库连接Connection对象 

Class.forName("com.mysql.jdbc.Driver");

String url = "jdbc:mysql://localhost:3306/mytest";

String user = "root";

String password = "123456";

Connection conn = DriverManager.getConnection(url, user, password);

//报表编译之后生成的.jasper文件的存放位置 

File reportFile = new File(this.getServletContext().getRealPath(

"/user3.jasper"));

//设置参数 

Map parameters = new HashMap();

try {

//执行报表程序 

System.out.println("---------conn-------------");

JasperRunManager.runReportToHtmlFile(reportFile,ctxpath,parameters,conn);

System.out.println("---------conn-------------");

response.sendRedirect(ctxpath + "/myreport.html");


System.out.println("---------conn-------------");

} catch (Exception e) {

System.out.println("---------conn-------------");

System.out.println(e.getMessage());

} finally {

try {

conn.close();

} catch (Exception ex) {

System.out.println(ex.getMessage());


}

}

%>

因为在JSP页面中 runReportToHtmlFile这个方法就报错,说我的第一个参数应该为String

举报
sweettime
发帖于5年前 1回/1K+阅
顶部