JasperReports生成html格式走样

yefeng177 2005-10-21 11:03:24
请教一下诸位,我使用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)
{
//错误处理... ...
}

}
...全文
250 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
windgoogle 2005-11-05
  • 打赏
  • 举报
回复
IMAGES_URI是可以配置的,在JasperReports包里有个J2EE包里有个ImageServlet,在web.xml配置其映射即可
yefeng177 2005-10-27
  • 打赏
  • 举报
回复
不是吧,一个回复都没有?what's wrong with CSDN?
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=");

81,091

社区成员

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

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