I am using java to create a line chart png file using jfree. The code first presents a port for processing the request, a browser opens the port, an image is created then the java code sends html back the browser with a reference (<IMG SRC=\"images/receiverevent.png\" BORDER=1/>) to the file created.
Thing is, doesn't display the image.
All other html elements display OK and If I save the html source from the browser into a local file (say showme.html) and open it the image is displayed. So, the html I am generating appears OK.
Anyone else seen this issue, have any idea how to resolve??
More details:
code to generate chart.
JFreeChart barChartObject = ChartFactory.createBarChart( "Reciever Event Totals", // chart title "Event", // domain axis label "Volume", // range axis label bar_chart_dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips? false // URLs? ); width=640; /* Width of the image */ height=240; /* Height of the image */ File barChart=new File("images//receivereventBC.png"); ChartUtilities.saveChartAsPNG(barChart,barChartObject,width,height);
Output: creates a file in the images directory...
code which generates html from program to browser...
BufferedOutputStream outStream = new BufferedOutputStream(clientConnection.getOutputStream()); String barChartImgSrc = "<IMG SRC=\"images/receivereventBC.png\" BORDER=1/>"; String responseMsg = "HTTP/1.1 200 OK\r\n" + "Content-Type: text/html; charset=UTF-8\r\n" + "Content-Length: 188\r\n" + "Connection: Close\r\n\r\n" + "<html>\r\n" + "<title>Stub Monitoring Page</title>\r\n" + "<body>\r\n" + "<h1>Bar Chart</h1><br>\r\n" + barChartImgSrc + "<br>\r\n" + "</body>\r\n" + "</html>\r\n"; outStream.write(responseMsg.getBytes()); outStream.flush(); outStream.close(); inStream.close(); clientConnection.close();HTML captured from the browsers View Source...
<html> <title>Stub Monitoring Page</title> <body> <h1>Bar Chart</h1><br> <IMG SRC="images/receivereventBC.png" BORDER=1/><br> </body> </html>What the browser displays
http://imageshack.com/a/img839/4204/ebc2.png
- what the browser displays after i've saved above html code to a text file showme.html
http://imageshack.com/a/img837/4549/asxb.png
I suspect I have some sort of relative path issue so I changed these lines
File barChart=new File("images//receivereventBC.png");
String barChartImgSrc = "<IMG SRC=\"images/receivereventBC.png\" BORDER=1/>";
to
File barChart=new File("D://Dropbox//java//20140529_httpStub//images//receivereventBC.png");
String barChartImgSrc = "<IMG SRC=\"D://Dropbox//java//20140529_httpStub//images//receivereventBC.png\" BORDER=1/>";
But the same effects as previously occurred..
Solved it: cant load external resources in modern browsers.
I'll need some other way, might need to setup an actual web server...