我正在使用Jasper报告6.我一直在创建带有图像的报告。此图片位于我当地的车道。我尝试从我的应用程序项目中调用此报告。当我在应用程序中运行时,图像不会出现。但它出现在贾斯珀。 如何设置图像路径以显示在我的应用程序根目录而不是本地驱动器?
我尝试使用像这样的图像参数,但它仍然是错误:
if (message.equalsIgnoreCase("PrintAlasanPenolakan")) {
File reportFile = new File(getServletConfig().getServletContext().getRealPath("/WEB-INF/reports/reportListAlasanPenolakan.jasper"));
byte[] bytes = null;
try {
dataReportAlasanPenolakan = dbReportAlasanPenolakan.getAllAlasanPenolakanReport();
Map model = new HashMap();
model.put("user", (String) session.getAttribute("user_id"));
model.put ("Image", (String) this.getServletConfig().getServletContext().getRealPath("/WEB-INF/reports/logo.png"));
bytes = JasperRunManager.runReportToPdf(reportFile.getPath(), model, new JRBeanCollectionDataSource(dataReportAlasanPenolakan));
response.setContentType("application/pdf");
response.setContentLength(bytes.length);
servletOutputStream.write(bytes, 0, bytes.length);
servletOutputStream.flush();
servletOutputStream.close();
} catch (Exception e) {
log.info("Error Print PDF:" + e.getMessage());
StringWriter stringWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(stringWriter);
e.printStackTrace(printWriter);
response.setContentType("text/plain");
response.getOutputStream().print(stringWriter.toString());
} finally {
dbConn.closeConnection();
}
}