1

I know that there is many similar post to this. But I didn't find any complete code of how to display JFreeChart to the <img> tag.

I'm displaying the image onload of the page.

NOTE: The URL this page is:

@RequestMapping( value = "/admin/student", method = RequestMethod.GET )

At the same page I'm trying to get the image onload with different URL mapping. ( I don't if this is possible but the URL mapping I think where the error is )

<div class="chart-image">
    <img src="../admin/student/getChart.do" class="img-rounded" />
</div>

The controller that render the chart is this:

@RequestMapping( value = "/{prePath:^tutor$|^admin$}/student/getChart", method = RequestMethod.GET )
public void displayChart( HttpServletResponse response )
{
    response.setContentType( "image/png" );
    try
    {
        JFreeChart chart = getChart();
        ChartUtilities.writeChartAsPNG( response.getOutputStream(), chart, 600, 400 );
        response.getOutputStream().close();
    }
    catch( IOException e )
    {
        // no logger yet
        e.printStackTrace();
    }
}

I'm getting this message from my console:

WARNING: No mapping found for HTTP request with URI [/ThesisProject/admin/student/getChart.do] in DispatcherServlet with name 'ThesisProject'

I don't get it why does my <img> tag doesn't seems see the controller that suppose to render the chart.

1 Answers1

0

You have a .do extension in your URL but not in your @RequestMapping, so change your mapping to include it:

@RequestMapping( value = "/{prePath:^tutor$|^admin$}/student/getChart.do", method = RequestMethod.GET )

Or your could always remove the .do extension from the URL in the <img> tag, but it depends on how you are mapping the DispatcherServlet in web.xml (ie. *.do)

John Farrelly
  • 7,289
  • 9
  • 42
  • 52