JasperReports生成html格式走样

yefeng177 yefeng177 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
请教一下诸位,我使用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)
{
//错误处理... ...
}

}
...全文

相关推荐

评论 5
收藏 已收藏
分享
返回顶部
yefeng177
Java EE 67,535 成员 225,843 内容