简体   繁体   English

运行Tomcat服务器的相对路径问题

[英]Relative Path Question Running a Tomcat Server

So I have a file structure like below 所以我有一个像下面这样的文件结构

http://dl.dropbox.com/u/322696/FolderPath.JPG 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. 当我启动Tomcat服务器时,如果我只是在服务器窗口中启动服务器并访问jsp文件夹中的jsp页面,我正在尝试找出它的根文件夹的起始位置。 I need to navigate to images/banner/name.jpg (trying to make an image file). 我需要导航到images / banner / name.jpg(尝试制作图像文件)。 I've set the servers context to '/projectname' (the black rectangle next to [repository]). 我已将服务器上下文设置为'/ projectname'([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? 您是否在询问如何从tomcat中获取磁盘路径? If so you use the ServletContext. 如果是这样,您使用ServletContext。

getServletContext().getRealPath("/") getServletContext()方法。getRealPath( “/”)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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