File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes Problems with writing image on server side Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Problems with writing image on server side" Watch "Problems with writing image on server side" New topic

Problems with writing image on server side

Peng Fan
Ranch Hand

Joined: May 04, 2004
Posts: 35
Hello everyone!
Recently, I'am working on a JSP project, in that project, I'm responsible for building a .png file and saved it on a hard disk with JFreeChart on the server side(the server is Tomcat 5.0.28),and then insert the .png file into a jsp page using a customized tag lib, in effect, that tag only return the absolute path of that .png file. Here is the complete code:

some fraction of my jsp file is:
but when I run the application, only me can see the image(since the Tomcat is installed on my computer), the image always stored under the {tomcat_home}/bin dir, rather than the com.amoysa.tag package.
My question is how can I solve this problem, let others see the png image.
leon fan

Joined: Aug 02, 2004
Posts: 19
The reason that all png file created under bin directory is caused by your code:
private String temppath = new File(".").getAbsolutePath();private String path = temppath.substring(0,temppath.length()-2);private String chartPath = path + "\\chart.png";

You can use the member 'pageContext' in TagSupport, then get ServletContext , call 'getRealPath' and change the root directory of your png under your web application's directory.
I agree. Here's the link:
subject: Problems with writing image on server side
jQuery in Action, 3rd edition