最近遇到一个问题,用ireport做报表生成饼图,我是这么做的
List satisfyReportCareerList = reportservice
.querySatisfyResultByCareer("2011062909021110967501");
int length2 = satisfyReportCareerList.size();
for (int m = 0; m < length2; m++) {
Map map2 = (Map) satisfyReportCareerList.get(m);
String careertype = map2.get("careertype").toString();
Double percentage = Double.valueOf(map2.get("percentage").toString());
params.put("careertype", careertype);
params.put("percentage", percentage);
}
JasperPrint jasperPrint2 = JasperFillManager.fillReport(appRealPath
+ "/webpage/report/tool/reportcareer.jasper", params,
new JRBeanCollectionDataSource(satisfyReportCareerList));
String reportFilePath2 = "report/tool/reportcareer.html";
String htmlReportFilePath2 = appRealPath + reportFilePath2;
JasperExportManager.exportReportToHtmlFile(jasperPrint2,
htmlReportFilePath2);
return "/report/tool/satisfyAllDetaiReport"; 在前台用iframe嵌套显示出生成的reportcareer.html这个页面,我在本地打开这个页面,会显示出我生成的饼图,是因为在同一个目录下有ireport生成的px样式,但是我在tomcat下打开这个页面,却看不到我生成的饼图,查看页面源码,看到的不是图片,而是ireport自已封装的一些px,<img alt="" src="reportposition.html_files/px" style="width: 20px; height: 1px;"/>,我感觉好像是没有样式所以导致这样的,我怎么才能在项目里把图片给显示出来啊,有做过这方面的大哥大姐吗,帮小弟一把,好几天了,谢谢了
List satisfyReportCareerList = reportservice
.querySatisfyResultByCareer("2011062909021110967501");
int length2 = satisfyReportCareerList.size();
for (int m = 0; m < length2; m++) {
Map map2 = (Map) satisfyReportCareerList.get(m);
String careertype = map2.get("careertype").toString();
Double percentage = Double.valueOf(map2.get("percentage").toString());
params.put("careertype", careertype);
params.put("percentage", percentage);
}
JasperPrint jasperPrint2 = JasperFillManager.fillReport(appRealPath
+ "/webpage/report/tool/reportcareer.jasper", params,
new JRBeanCollectionDataSource(satisfyReportCareerList));
String reportFilePath2 = "report/tool/reportcareer.html";
String htmlReportFilePath2 = appRealPath + reportFilePath2;
JasperExportManager.exportReportToHtmlFile(jasperPrint2,
htmlReportFilePath2);
return "/report/tool/satisfyAllDetaiReport"; 在前台用iframe嵌套显示出生成的reportcareer.html这个页面,我在本地打开这个页面,会显示出我生成的饼图,是因为在同一个目录下有ireport生成的px样式,但是我在tomcat下打开这个页面,却看不到我生成的饼图,查看页面源码,看到的不是图片,而是ireport自已封装的一些px,<img alt="" src="reportposition.html_files/px" style="width: 20px; height: 1px;"/>,我感觉好像是没有样式所以导致这样的,我怎么才能在项目里把图片给显示出来啊,有做过这方面的大哥大姐吗,帮小弟一把,好几天了,谢谢了
解决方案 »
- js数组怎么利用jquery ajax怎么传到java后台,后台怎么接受啊。。
- struts 2.0拦截器如何进行权限验证,实现某些登录的用户能访问,别的不能访问该页面
- 有velocity+ssh开发经验的兄弟们进来研究下,等待...
- java实现生成excel文件并加密 文件打开时需要输入密码才能访问 谢谢!
- 异常拦截,JSON拦截
- 谁有map的详细用法!分享下!谢谢各位大哥大姐了!~~~
- 类文件做过改动后部署到tomcat下,运行程序发现没有改动后的效果
- webliic connectionpool 的小问题(在线等)
- Hibernate中调用删除的时候产生 could not execute native bulk manipulation query异常怎么解决?
- 急!提示:34:cannot resolve symbol symbol:class ht location:class mservlet
- MongoDB存储字符串时的问题
- 跨域验证的问题
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_STRING_BUFFER, sbuffer);
exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, "servlets/image?radom="+Math.random()+"&image=");
exporter.setParameter(JRHtmlExporterParameter.HTML_HEADER, "");
exporter.setParameter(JRHtmlExporterParameter.BETWEEN_PAGES_HTML, "");
exporter.setParameter(JRHtmlExporterParameter.HTML_FOOTER, "");
exporter.setParameter(JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN, Boolean.FALSE);
exporter.exportReport();
web.xml中,加上:
<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>/servlets/image</url-pattern>
</servlet-mapping>
JasperPrint jasperPrint = JasperFillManager.fillReport(appRealPath
+ "webpage/report/tool/reportposition.jasper", params,
new JRBeanCollectionDataSource(satisfyReportList));
String reportFilePath = "report/tool/reportposition.html";
String htmlReportFilePath = appRealPath + reportFilePath;
// JasperExportManager.exportReportToHtmlFile(jasperPrint,
// htmlReportFilePath);
JRHtmlExporter exporter = new JRHtmlExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_STRING_BUFFER, htmlReportFilePath);
exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, "servlets/image?radom="+Math.random()+"&image=");
exporter.setParameter(JRHtmlExporterParameter.HTML_HEADER, "");
exporter.setParameter(JRHtmlExporterParameter.BETWEEN_PAGES_HTML, "");
exporter.setParameter(JRHtmlExporterParameter.HTML_FOOTER, "");
exporter.setParameter(JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN, Boolean.FALSE);
exporter.exportReport();
走最后一步的时候报错,错误如下:
java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.StringBuffer
at net.sf.jasperreports.engine.export.JRHtmlExporter.exportReport(JRHtmlExporter.java:447)
at com.izhong.information.app.boss.tool.controller.satisfy.ToolSatisfyReportController.exportPosition(ToolSatisfyReportController.java:81)
at com.izhong.information.app.boss.tool.controller.satisfy.ToolSatisfyReportController.satisfyReport(ToolSatisfyReportController.java:42)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:436)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:424)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:790)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:549)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.izhong.information.appbase.web.filters.CustomerAccountsVisitFilter.doFilter(CustomerAccountsVisitFilter.java:81)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
at java.lang.Thread.run(Thread.java:619)
StringBuffer sbuffer = new StringBuffer();