设置图片是这样做的,我在ireport里设置了一个参数$P{mages}参数名为mages,参数的类型是数据流类型,在报表上放了一个图片框,图片框的路径不是得到图片的路径而是这个参数$P{mages}。是在jsp页面为这个个参数传入数据留,
String imageRead = request.getRealPath( "WEB-INF/logon.jpg ");//获得图片路径File imageFile = new File(imageRead);
InputStream imageIn = new FileInputStream(imageFile);//图片一个数据流
parameters.put( "logo ",imageIn);//获得为图片设置的参数,把图片传给这个参数
这样为图片参数传值的,整个程序不报错,只是在jsp里看不到图片的效果,保存为其他的格式能看见这个图片。在jsp里右击不显示的图片属性看到的路径是:http://localhost:8083/servlets/imagesdir=img_0_0_1
十万火急,大家帮我看看吧。
4 个解决方案
#1
参数传递到xxx.jasper之后,你是怎样处理的,把那段代码拿出来看看???
(你应该在ireport那里做处理的)
(你应该在ireport那里做处理的)
#2
我是这样做的。
//生成html
JRHtmlExporter exporter = new JRHtmlExporter();
ByteArrayOutputStream oStream = new ByteArrayOutputStream();
JasperPrint jasperPrint = JasperFillManager.fillReport(rpt.getPath(), map, con);
exporter.setParameter(JRHtmlExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRHtmlExporterParameter.CHARACTER_ENCODING, "utf-8");
exporter.setParameter(JRHtmlExporterParameter.OUTPUT_STREAM, oStream);
exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, request.getContextPath()+"/servlets/image?image=");
exporter.setParameter(JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN, Boolean.FALSE);
exporter.exportReport();//导出
exporter.exportReport();
byte[] bytes = oStream.toByteArray();
response.setContentType("text/html");
response.setContentLength(bytes.length);
response.setCharacterEncoding("utf-8");
ServletOutputStream ouputStream = response.getOutputStream();
ouputStream.write(bytes, 0, bytes.length);
ouputStream.flush();
ouputStream.close();
con.close();
out.clear();
out = pageContext.pushBody();
//生成html
JRHtmlExporter exporter = new JRHtmlExporter();
ByteArrayOutputStream oStream = new ByteArrayOutputStream();
JasperPrint jasperPrint = JasperFillManager.fillReport(rpt.getPath(), map, con);
exporter.setParameter(JRHtmlExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRHtmlExporterParameter.CHARACTER_ENCODING, "utf-8");
exporter.setParameter(JRHtmlExporterParameter.OUTPUT_STREAM, oStream);
exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, request.getContextPath()+"/servlets/image?image=");
exporter.setParameter(JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN, Boolean.FALSE);
exporter.exportReport();//导出
exporter.exportReport();
byte[] bytes = oStream.toByteArray();
response.setContentType("text/html");
response.setContentLength(bytes.length);
response.setCharacterEncoding("utf-8");
ServletOutputStream ouputStream = response.getOutputStream();
ouputStream.write(bytes, 0, bytes.length);
ouputStream.flush();
ouputStream.close();
con.close();
out.clear();
out = pageContext.pushBody();
#3
JRHtmlExporter exporter = new JRHtmlExporter();
#4
同样遇到这个问题,不知道怎么解
#1
参数传递到xxx.jasper之后,你是怎样处理的,把那段代码拿出来看看???
(你应该在ireport那里做处理的)
(你应该在ireport那里做处理的)
#2
我是这样做的。
//生成html
JRHtmlExporter exporter = new JRHtmlExporter();
ByteArrayOutputStream oStream = new ByteArrayOutputStream();
JasperPrint jasperPrint = JasperFillManager.fillReport(rpt.getPath(), map, con);
exporter.setParameter(JRHtmlExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRHtmlExporterParameter.CHARACTER_ENCODING, "utf-8");
exporter.setParameter(JRHtmlExporterParameter.OUTPUT_STREAM, oStream);
exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, request.getContextPath()+"/servlets/image?image=");
exporter.setParameter(JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN, Boolean.FALSE);
exporter.exportReport();//导出
exporter.exportReport();
byte[] bytes = oStream.toByteArray();
response.setContentType("text/html");
response.setContentLength(bytes.length);
response.setCharacterEncoding("utf-8");
ServletOutputStream ouputStream = response.getOutputStream();
ouputStream.write(bytes, 0, bytes.length);
ouputStream.flush();
ouputStream.close();
con.close();
out.clear();
out = pageContext.pushBody();
//生成html
JRHtmlExporter exporter = new JRHtmlExporter();
ByteArrayOutputStream oStream = new ByteArrayOutputStream();
JasperPrint jasperPrint = JasperFillManager.fillReport(rpt.getPath(), map, con);
exporter.setParameter(JRHtmlExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRHtmlExporterParameter.CHARACTER_ENCODING, "utf-8");
exporter.setParameter(JRHtmlExporterParameter.OUTPUT_STREAM, oStream);
exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, request.getContextPath()+"/servlets/image?image=");
exporter.setParameter(JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN, Boolean.FALSE);
exporter.exportReport();//导出
exporter.exportReport();
byte[] bytes = oStream.toByteArray();
response.setContentType("text/html");
response.setContentLength(bytes.length);
response.setCharacterEncoding("utf-8");
ServletOutputStream ouputStream = response.getOutputStream();
ouputStream.write(bytes, 0, bytes.length);
ouputStream.flush();
ouputStream.close();
con.close();
out.clear();
out = pageContext.pushBody();
#3
JRHtmlExporter exporter = new JRHtmlExporter();
#4
同样遇到这个问题,不知道怎么解