HkFreaKuser1673718
HkFreaKuser1673718

Reputation: 747

trying to show image on my jsp in war file format

i am making a web application which plots graph based on the date from database i use jfreechart and saving the graph as a image.And trying to display it on my jsp page by specifing the image path.

in jsp i am givin this

<img src="C:/Program Files/Apache Software Foundation/Tomcat 7.0/webapps/yeargraph.jpg" class="myimageclass" alt="Graph Cannot be Displayed Due to some internal error"/>

inside my jfreechart program i give

String fileName="C:/Program Files/Apache Software Foundation/Tomcat 7.0/webapps/yeargraph.jpg";

to save chart i am able to save the graph and display it on my jsp file if i run project in my eclipse Indigo but if i export it to a WAR file and paste WAR file in Tomcat/webapps/folder and then run brwoser "localhost:8080/projetcname/" i can see my project working fine But if I try to plot graph its is not showing the image in my jsp page y is it so am i doing something wrong pleas ehelp thanks in advance.

Note:Based the users input my application will generate different graphs by overwriting same image file so even this should be taken care of

Upvotes: 0

Views: 625

Answers (3)

herrtim
herrtim

Reputation: 2755

I would recommend Flot for web-based charting even over my own open source API XChart, which is geared more towards desktop applications. Here is a HelloWorld type example application with source code demonstrating Flot that I made at one point. If more you're more interested in fetching a JPEG containing a chart, you can see how I do it with XChart (Bonus Example, bottom of page), and you could probably do something very similar with JFreeChart without even needing to save the jpeg to disk first.

Upvotes: 0

goncaloGomes
goncaloGomes

Reputation: 163

You will have all kinds of problems when you deploy that to a production server. Try a different aproach: - find a folder you know you will have permissions when in production; - give jfreechart the path "[folder with permissions]/charts_temp_folder/yeargraph.jpg"; - write a small servlet to read the file and serve it; - point your jsp to that folder;

Let us know how that goes.

Upvotes: 1

Sanket
Sanket

Reputation: 393

To get the absolute file path by just searching for the file name you can try this

   String yeargraph= new ClassPathResource("yeargraph.jpg").getFile().getAbsolutePath();

Upvotes: 0

Related Questions