问题描述
可以给个jasper ireport生成图片的例子的代码例子吗?我的怎么就是显示不出来呢 问题补充:不好意思没说明白我的是生成excle的啊 这是我的代码Map parameters = new HashMap();String path7 = req.getRealPath("") +"/congress/deputy/photo/"+attach;parameters.put("IMAGE_DIR",path7); try{JasperFillManager.fillReportToFile(path + ".jasper", parameters,new CustomDataSource(temp.iterator(), field));} catch (Exception e) { e.printStackTrace();}File sourceFile = new File(path + ".jrprint"); JasperPrint jasperPrint = (JasperPrint) JRLoader.loadObject(sourceFile);File destFile = new File(sourceFile.getParent(), jasperPrint.getName()+ ".xls"); JRAbstractExporter exporter=new JExcelApiExporter();exporter.setParameter(JRExporterParameter.JASPER_PRINT,jasperPrint);exporter.setParameter(JRExporterParameter.OUTPUT_STREAM,new FileOutputStream(destFile.toString()));exporter.exportReport();url.append(".xls");}catch (Exception e) {e.printStackTrace(); } res.sendRedirect(url.toString());问题补充:这是报的错误java.lang.IllegalAccessError: tried to access field com.keypoint.PngEncoder.encodeAlpha from class com.keypoint.PngEncoderBcom.keypoint.PngEncoderB.<init>(PngEncoderB.java:127)com.keypoint.PngEncoderB.<init>(PngEncoderB.java:78)net.sf.jasperreports.engine.export.JExcelApiExporter.<init>(JExcelApiExporter.java:138)com.egov.congress.deputy.report.DeputyGuoReport.doPost(DeputyGuoReport.java:262)javax.servlet.http.HttpServlet.service(HttpServlet.java:709)javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
解决方案
需要在你的web.xml中配置image生成器<servlet><servlet-name>ImageServlet</servlet-name><servlet-class>net.sf.jasperreports.j2ee.servlets.ImageServlet</servlet-class></servlet><servlet-mapping><servlet-name>ImageServlet</servlet-name><url-pattern>/image</url-pattern></servlet-mapping>然后你的Export中设置如下:public void export(HttpServletRequest request,HttpServletResponse response, String reportFilePath, Map params,JRDataSource dataSource) {try {PrintWriter out = response.getWriter();try {response.setContentType("text/html;charset=UTF-8");JasperPrint jasperPrint = new JasperPrintWithDataSource(reportFilePath, params, dataSource).getJasperPrint();// 使用JRHtmlExproter导出Html格式JRHtmlExporter exporter = new JRHtmlExporter();request.getSession().setAttribute(ImageServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE,jasperPrint);exporter.setParameter(JRExporterParameter.JASPER_PRINT,jasperPrint);exporter.setParameter(JRExporterParameter.OUTPUT_WRITER, out);exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI,[color=red]"./image?image="[/color]);exporter.setParameter(JRExporterParameter.CHARACTER_ENCODING,"UTF-8");exporter.setParameter(JRHtmlExporterParameter.BETWEEN_PAGES_HTML, "");exporter.setParameter(JRHtmlExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS,Boolean.TRUE);// 导出exporter.exportReport();} catch (Exception e) {e.printStackTrace();} finally {if (out != null) {try {out.close();} catch (Exception e) {}}}} catch (IOException ioe) {ioe.printStackTrace();}}
解决方案二:
这个问题的话,用帆软报表做也是很方便的
解决方案三:
com.egov.congress.deputy.report.DeputyGuoReport.doPost(DeputyGuoReport.java:262) 这一行有错误,这一行是哪句
解决方案四:
能把你的代码贴出来吗?