简体   繁体   中英

Relative Path Question Running a Tomcat Server

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?

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

getServletContext().getRealPath("/")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM