关于JasperReport的问题
tsylo 2006-03-08 11:22:45 我在使用这个开源工具的时候,按照网上写了一段程序,可是出现了很多问题,具体问题如下:
我开始的时候使用IReport0.3.2版本,正常编译,并且生成了jasper文件,但是用于web程序中
生成pdf文档时,缺发现pdf文档是空的,无奈,我下载了个新的IReport0.5.3,这次编译也成功
了,也生成了jasper文件,但是用程序运行时候却报错:
JRException:Class not found when loading object from file : E:\alex\project\TestReport\WebPage\test\untitled_report_1.jasper
我的代码如下:
package com.topsign.report;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.sql.Connection;
import dori.jasper.engine.*;
public class test extends HttpServlet
{
private static final String CONTENT_TYPE = "text/html; charset=GBK";
//Initialize global variables
public void init() throws ServletException
{
}
//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
try
{
ServletContext servletContext =this.getServletContext();
File reportFile = new File(servletContext.getRealPath("test/untitled_report_1.jasper"));
System.out.println(reportFile.getPath());
Map parameters = new HashMap();
Connection conn = DataBase.getConnection();
JasperRunManager run = new JasperRunManager();
byte bytes[] = run.runReportToPdf(reportFile.getPath(),parameters,conn);
response.setContentType("application/pdf");
response.setContentLength(bytes.length);
ServletOutputStream outputStream = response.getOutputStream();
outputStream.write(bytes,0,bytes.length);
System.out.println("write success!");
outputStream.flush();
outputStream.close();
}
catch (JRException jre)
{
System.out.println("JRException:" + jre.getMessage());
}
catch (Exception e)
{
System.out.println("Exception:" + e.getMessage());
}
}
//Clean up resources
public void destroy()
{
}
}
请教高手,十分感谢,分不够再加,在线等。