Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problems with writing image on server side

 
Peng Fan
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic