关于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()
{
}
}
请教高手,十分感谢,分不够再加,在线等。

...全文
117 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
tsylo 2006-03-08
  • 打赏
  • 举报
回复
迷糊,就算换个版本得ireport,没有这个异常乐,通过程序产生得pdf文档却是一片空白。。。
tsylo 2006-03-08
  • 打赏
  • 举报
回复
有人会jasperreport么?。。。。。。
初次运行就这里出错那里出错的,这个开源的东西真是。。。。。
据说这个错误是因为编译xml文件时候的jasperreport的版本和工程中使用
的jasperreport.jar的版本不一致导致的,可我整个电脑上就这么一个0.5.3的jar包啊
tsylo 2006-03-08
  • 打赏
  • 举报
回复
回复ricky414-
1,程序肯定没有问题,断点到byte bytes[] = run.runReportToPdf(reportFile.getPath(),parameters,conn);这句话跳出

2,工程中有itext包

3,目前没有连接数据库,就是用的静态的。
ricky414 2006-03-08
  • 打赏
  • 举报
回复
ireport很久没有用过了,给你一些提议,看能否有帮助

1,检查程序是否有问题,用断点调试的方法跟踪

2,检查工程中是否有itext包?

3,在设计pdf格式的输出的时候你先放一写静态文本进去看看,最后输出的时候这些东西在不在

如果以上你都确定有,那再把问题反映过来,再研究看看。
tsylo 2006-03-08
  • 打赏
  • 举报
回复
无论怎么做,用web程序(jasperReport)打开的pdf文档都是空白的,。。。。。有人帮忙给个建议么

81,122

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧