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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于刚入门的初学者来说,FineReport更适合使用,操作界面简单,用起来更容易一些
官方网址:http://www.finereport.com/
下载地址:http://www.finereport.com/products/trial