首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Exception >

Unable to compile class for JSP解决方法!

2014-01-26 
我的jsp代码是: [code] %@ page contentType application/pdfcharsetGB2312 % %@ page import ja

我的jsp代码是:
[code]
<%@ page contentType= "application/pdf;charset=GB2312 "%>
<%@ page import= "java.io.* " %>
<%@ page import= "java.sql.* " %>
<%@ page errorPage= "error.jsp " %>
<%@ page import= "datasource.* " %>
<%@ page import= "net.sf.jasperreports.engine.* " %>
<%@ page import= "net.sf.jasperreports.engine.util.* " %>
<%@ page import= "net.sf.jasperreports.engine.export.* " %>
<%@ page import= "net.sf.jasperreports.j2ee.servlets.* " %>
<%@ page import= "java.util.* " %>
<%
//报表编译之后生成的.jasper 文件的存放位置
File reportFile = new File(application.getRealPath( "try0821.jasper "));
//这个是用来联接我的SQL Server 的JDBC URL
String url = "jdbc:mysql://localhost/firstdb ";
Class.forName( "com.mysql.jdbc.Driver ").newInstance();
//传递报表中用到的参数值
Map parameters = new HashMap();
// "Name "是报表中定义过的一个参数名称,其类型为String 型
parameters.put( "Name ", new String( "江敏 "));
System.out.println( "---------conn------------- ");
//连接到数据库
Connection conn = DriverManager.getConnection(url, "root ", "060413 ");
System.out.println( "---------Jasper begin------------- ");
//在控制台显示一下报表文件的物理路径
System.out.println(reportFile.getPath());
byte[] bytes=JasperRunManager.runReportToPdf(reportFile.getResourceAsStream(),parameters,conn);
System.out.println( "---------Jasper end------------- ");
response.setContentType( "application/pdf ");
response.setContentLength(bytes.length);
ServletOutputStream ouputStream = response.getOutputStream();
ouputStream.write(bytes, 0, bytes.length);
ouputStream.flush();
ouputStream.close();
%>
[/code]

在tomcat下浏览提示错误:

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

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

An error occurred at line: 27 in the jsp file: /try0821.jsp
The method getResourceAsStream() is undefined for the type File
24: System.out.println( "---------Jasper begin------------- ");
25: //在控制台显示一下报表文件的物理路径
26: System.out.println(reportFile.getPath());
27: byte[] bytes=JasperRunManager.runReportToPdf(reportFile.getResourceAsStream(),parameters,conn);
28: System.out.println( "---------Jasper end------------- ");
29: response.setContentType( "application/pdf ");
30: response.setContentLength(bytes.length);


Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:85)
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:299)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:315)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)

望高手或碰到类似情况的好心人指点。

------解决方法--------------------------------------------------------
jsp页面都没编译成功。。。。。。。
The method getResourceAsStream() is undefined for the type File
File类没有该方法的定义。。。
我以前用过写法如下:
JasperReport jasperReport = (JasperReport)JRLoader.loadObject(reportFile.getPath());         

热点排行