JasperReports生成html格式走样

yefeng177 2005-10-21 11:02:39
请教一下诸位,我使用ireport0.5.1生成的html格式是正常的
如下面网址所示
http://www.hyweb.net/Public/test1.mht

但是当我试图使用jasperreports1.0.1从jsp/servlet中生成的时候
虽然数据依然正确,但是html的格式完全走样了,如下
http://www.hyweb.net/Public/test2.mht

不知道空的那些图片是什么意思,我的jsp与servlet都是参照了
jasperreports中的demo代码,现贴出servlet中的代码,请大家参考帮忙

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

ServletContext context = this.getServletConfig().getServletContext();

response.setContentType("text/html;charset=GB2312");
PrintWriter out = response.getWriter();
Connection conn = null;

System.out.println("Ready to report File...");

String url ="jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=swoa20";
try {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
conn = DriverManager.getConnection(url,"sa", "");

} catch (InstantiationException e1) {
e1.printStackTrace();
} catch (IllegalAccessException e1) {
e1.printStackTrace();
} catch (ClassNotFoundException e1) {
e1.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}


try
{
File reportFile = new File(context.getRealPath("/report/hytest1.jasper"));
if (!reportFile.exists())
throw new JRRuntimeException("File WebappReport.jasper not found. The report design must be compiled first.");

JasperReport jasperReport = (JasperReport)JRLoader.loadObject(reportFile.getPath());

Map parameters = new HashMap();

JasperPrint jasperPrint =
JasperFillManager.fillReport(
jasperReport,
parameters,
conn
);

JRHtmlExporter exporter = new JRHtmlExporter();

Map imagesMap = new HashMap();
request.getSession().setAttribute("IMAGES_MAP", imagesMap);

exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_WRITER, out);
exporter.setParameter(JRHtmlExporterParameter.IMAGES_MAP, imagesMap);
exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, "image?image=");

exporter.exportReport();
}
catch (JRException e)
{
//错误处理... ...
}

}
...全文
269 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
hant 2005-11-16
  • 打赏
  • 举报
回复
我遇到过的是图片的路径没有设正确,会出现乱的图片框,后来调整了设置,好了!
yefeng177 2005-10-27
  • 打赏
  • 举报
回复
CSDN怎么了?
bitou 2005-10-27
  • 打赏
  • 举报
回复

jasperreport好久没研究了,纯友情UP
yefeng177 2005-10-22
  • 打赏
  • 举报
回复
不是吧,又沉底了?最近在CSDN上面发的帖子沉的好快....大家随便聊聊对jasperreport的看法吧,就当散分了
yefeng177 2005-10-21
  • 打赏
  • 举报
回复
目前我找到的问题是缺少一个pixel.GIF图片
这个图片在jasper的jar包里面自带了的,但是图片里面找不到,没有办法,我只能将这几个文件拷贝出来放在jsp/servlet同级目录下,请问能不能指定IMAGES_URI呢,比如说指定到目录images下面,我没有找到对下面语句合适的修改方法。

Map imagesMap = new HashMap();
session.setAttribute("IMAGES_MAP", imagesMap);
exporter.setParameter(JRHtmlExporterParameter.IMAGES_MAP, imagesMap);
exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, "image.jsp?image=");

67,515

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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