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

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>();
            //set ImageHandler. Hack for images export to HTML
            SimpleHtmlExporterOutput output = new SimpleHtmlExporterOutput(response.getWriter());
            WebHtmlResourceHandler webHtmlResourceHandler =  new WebHtmlResourceHandler("image?image={0}");
            SimpleHtmlReportConfiguration configuration = new SimpleHtmlReportConfiguration();

Here is my web.xml :


Work Environment : Jasperreports 6.1.0, Spring 4.1.1, Eclipse Luna

vaidya.vallabh's picture
Joined: Apr 2 2013 - 4:10am
Last seen: 2 years 4 months ago

You can share code to export to PDF, with the new version 6.1, no longer works the routine that I have .

Thank you.


luisneiran - 7 years 3 months ago

1 Answer:

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


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

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

vaidya.vallabh's picture
Joined: Apr 2 2013 - 4:10am
Last seen: 2 years 4 months ago