Jump to content
Changes to the Jaspersoft community edition download ×

Jasperreports Spring : Chart is not being displayed when report exported as HTML


vaidya.vallabh

Recommended Posts

Developed a Simple Spring Maven Web application with Jsperreports 6.1.0 dependency. Created a Jasper report having a static text and a chart. When exported report in PDF format, report is printed properly with static text and chart, but when exported to HTML format only static text is displayed not chart.

After searching on internet found that ImageServlet and few parameters are needed to export report in HTML format.

Added ImageServlet mapping in web.xml

Set Image URI through WebHtmlResourceHandler.

Still report does not show chart. What is the problem?

Here is my Spring Controller code to export report in HTML format.

            List<BeanAuthorBooks> beanList = new ArrayList<BeanAuthorBooks>();            beanList.add(new BeanAuthorBooks("APJ Kalam",10));            beanList.add(new BeanAuthorBooks("Robin  Shamra",5));            beanList.add(new BeanAuthorBooks("Rashmi Bansal",8));            beanList.add(new BeanAuthorBooks("Dr. B.R.Ambedkar",60));            beanList.add(new BeanAuthorBooks("Mahatma Gandhi",15));                       Map<String,Object> params = new HashMap();            JasperReport jasperReport = JasperCompileManager.compileReport(this.getClass().getResourceAsStream("testreport.jrxml"));            JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, new JRBeanCollectionDataSource(beanList,false));            HtmlExporter exporter = new HtmlExporter();            List<JasperPrint> jasperPrintsList = new ArrayList<JasperPrint>();            jasperPrintsList.add(jasperPrint);            exporter.setExporterInput(SimpleExporterInput.getInstance(jasperPrintsList));            //set ImageHandler. Hack for images export to HTML            SimpleHtmlExporterOutput output = new SimpleHtmlExporterOutput(response.getWriter());            WebHtmlResourceHandler webHtmlResourceHandler =  new WebHtmlResourceHandler("image?image={0}");            output.setImageHandler(webHtmlResourceHandler);                       exporter.setExporterOutput(output);                        SimpleHtmlReportConfiguration configuration = new SimpleHtmlReportConfiguration();            exporter.setConfiguration(configuration);            exporter.exportReport();[/code]

Here is my 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>/image</url-pattern>    </servlet-mapping>[/code]

Work Environment : Jasperreports 6.1.0, Spring 4.1.1, Eclipse Luna

Link to comment
Share on other sites

  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

Found the problem.....POsting solution here....

Actually My Controller has requestmapping as  "/reports" and my method from which I was exporting report has request mapping "/html",

so final request for image being displayed in chart was becoming something like "appname/reports/html/image?image=img_0_1".

But ImageServlet was mapped with URL "/image" so updated my code as below :

In web.xml

<servlet-mapping>        <servlet-name>ImageServlet</servlet-name>        <url-pattern>/reports/image</url-pattern> </servlet-mapping>[/code]

 and in controller updated my url as ......

WebHtmlResourceHandler webHtmlResourceHandler =  new WebHtmlResourceHandler("../image?image={0}");[/code]

 

Link to comment
Share on other sites

  • 2 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...