JasperReports生成html格式走样
请教一下诸位,我使用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)
{
//错误处理... ...
}
}