3

So I have a file structure like below

http://dl.dropbox.com/u/322696/FolderPath.JPG

When I start the Tomcat Server, I'm trying to figure out where it's root folder begins with if I were just to start the server in the server window and access a jsp page within the jsp folder. I need to navigate to images/banner/name.jpg (trying to make an image file). I've set the servers context to '/projectname' (the black rectangle next to [repository]). I've tried like:

File image = new File("../images/banner/name.jpg"); //If its root was the jsp I accessed

No dice. Is there a method I could run to determine what the relative path should be?

B.Z.B
  • 471
  • 2
  • 10
  • 24

1 Answers1

4

Are you asking how to get the on disk path from within tomcat? If so you use the ServletContext.

getServletContext().getRealPath("/")

mattx
  • 245
  • 1
  • 10
  • I wanted to use a relative path such as '../images/etc' instead of an absolute path like 'C:\program\etc'. When trying to access the image. – B.Z.B Mar 15 '11 at 20:06
  • @BZB you're right that it would be absolute, but it would be dynamically generated, so it achieves the same goal. – corsiKa Mar 15 '11 at 20:10
  • Well like for instance this project is on CVS so someone else trying to run this would need a relative path...which I still am unsure what that would be. – B.Z.B Mar 15 '11 at 20:41
  • Hey thanks I got it working. http://stackoverflow.com/questions/3596501/absolute-to-relative-path-eclipse-jsp helped it make sense to me. – B.Z.B Mar 16 '11 at 18:14