gpt4 book ai didi

java - 在 JSP 上使用 JasperRunManager : JasperRunManager can not be resolved

转载 作者:行者123 更新时间:2023-12-01 13:49:49 25 4
gpt4 key购买 nike

我在使用 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)中的类。

关于java - 在 JSP 上使用 JasperRunManager : JasperRunManager can not be resolved,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20048104/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com