为你的形象,尝试表达类
'net.sf.jasperreports.engine.JRRenderable'
和类似的意象表现如下:
net.sf.jasperreports.engine.JRImageRenderer.getInstance("image-dir/report-logo.gif")
在碧玉报告文件(如myreport.jrxml)的表达该图像将如下所示:
对于Html报告,图像servlet可能是有用,可在web.xml中配置:
image
net.sf.jasperreports.j2ee.servlets.ImageServlet
image
/report/image
执行报告的Java/Spring代码,其中a.o.设置图像的URI图像的servlet:
public ModelAndView createReport(HttpSession session, String reportName, String format) {
ApplicationContext context = this.getApplicationContext();
JasperReportsMultiFormatView report = new CollegeJasperReportsMultiFormatView(session);
report.setUrl("/WEB-INF/reports/jasper/" + reportName + ".jasper");
Map model = getModel();
model.put("format", format);
Map parameters = new HashMap();
report.setExporterParameters(parameters);
parameters.put(JRExporterParameter.CHARACTER_ENCODING, "UTF8");
parameters.put(JRHtmlExporterParameter.IMAGES_URI, "../report/image?image=");
parameters.put(JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN, Boolean.FALSE);
Properties contentDispositionMappings = new Properties();;
contentDispositionMappings.put(format, "inline; filename=report." + format);
report.setContentDispositionMappings(contentDispositionMappings);
report.setApplicationContext(context); // this will convert the export parameters, so has to be called after setExportParameters()
return new ModelAndView(report, model);
}