我的JasperReports 2.0.5有问题,我想查看有关Web图形格式pdf的报告。
我正在写这些代码:
<% @ Page errorPage = " error.jsp "% >
<% @ Page import = " net.sf.jasperreports.engine . * "% >
<% @ Page import = " net.sf.jasperreports.engine.util . * "% >
<% @ Page import = " net.sf.jasperreports.engine.export . * "% >
<% @ Page import = " java.util . * "% >
<% @ Page import = " java.io. * "% >
<% @ Page import = " java.sql . * "% >
<% @ Page import = " javax.naming . * "% >
InitContext context = new InitialContext ();
EnvContext context = ( Context) initContext.lookup ( " java :/ comp / env ");
DataSource ds = (DataSource) envContext.lookup ( " jdbcLink ");
Connection conn = ds.getConnection ();
/ / PDF View
ReportFile File = new File ( application.getRealPath ( "Reports / WebReport.jasper "));
Map parameters = new HashMap ();
byte [ ] bytes = JasperRunManager.runReportToPdf ( reportFile.getPath ( ) , parameters, conn ) ;
response.setContentType ( " application / pdf ");
response.setContentLength ( bytes.length ) ;
ServletOutputStream ouputStream = response.getOutputStream ();
ouputStream.write ( bytes , 0, bytes.length ) ;
ouputStream.flush ( ) ;
ouputStream.close ( ) ;
它给了我这个错误:
org.apache.jasper.JasperException : Unable to compile class for JSP :
An error occurred at line : 32 in the jsp file: / Reports / test.jsp
JasperRunManager can not be resolved
29 : File reportFile = new File ( application.getRealPath ( "Reports / WebReport.jasper "));
30 : Map parameters = new HashMap ();
31 : out.println ( parameters ) ;
32 : byte [ ] bytes = JasperRunManager.runReportToPdf ( reportFile.getPath ( ) , parameters , conn ) ;
33 : response.setContentType ( " application / pdf ");
34 : response.setContentLength ( bytes.length ) ;
35 : ServletOutputStream ouputStream = response.getOutputStream ();
Stacktrace :
org.apache.jasper.compiler.DefaultErrorHandler.javacError ( DefaultErrorHandler.java : 93)
org.apache.jasper.compiler.ErrorDispatcher.javacError ( ErrorDispatcher.java : 330 )
org.apache.jasper.compiler.JDTCompiler.generateClass ( JDTCompiler.java : 435 )
org.apache.jasper.compiler.Compiler.compile ( Compiler.java : 298)
org.apache.jasper.compiler.Compiler.compile ( Compiler.java : 277)
org.apache.jasper.compiler.Compiler.compile ( Compiler.java : 265)
org.apache.jasper.JspCompilationContext.compile ( JspCompilationContext.java : 564 )
org.apache.jasper.servlet.JspServletWrapper.service ( JspServletWrapper.java : 302 )
org.apache.jasper.servlet.JspServlet.serviceJspFile ( JspServlet.java : 329 )
org.apache.jasper.servlet.JspServlet.service ( JspServlet.java : 265)
javax.servlet.http.HttpServlet.service ( HttpServlet.java : 803 )
在lib文件夹中,我包含了以下jar:
-Groovy-all-1.0.jar
-IText-1.3.1.jar
-JasperReports-2.0.5.jar
-Poi-3.0.1-FINAL-20070705.jar
-Commons-beanutils-1.7.jar
-Commons-collections-2.1.jar
-Commons-logging-1.0.2.jar
对不起我的英语不好
最佳答案
您在JSP文件开始处的导入不正确。它们应具有以下格式:
<%@ page attribute="value" %>
(注意,页面不是页面)
因此,您应该拥有(删除重复项):
<%@ page errorPage="error.jsp" %>
<%@ page import="net.sf.jasperreports.engine.*" %>
<%@ page import="net.sf.jasperreports.engine.util.*" %>
<%@ page import="net.sf.jasperreports.engine.export.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.io.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="javax.naming.*" %>
由于它们的格式不正确,因此找不到导入包中的类(例如JasperRunManager)。