File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes how to get absolute path of linked resource outside of Tomcat Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "how to get absolute path of linked resource outside of Tomcat" Watch "how to get absolute path of linked resource outside of Tomcat" New topic
Author

how to get absolute path of linked resource outside of Tomcat

John Dunning
Greenhorn

Joined: Aug 31, 2004
Posts: 3
I'm trying to get the absolute path from a relative path. The problem is that the file I'm trying to access is not under the /Tomcat/ directory. Currently I can link to the file using a relative path, but I need to use the File object to iterate through the files in the directory.

For clarification, I'm running cruisecontrol on Tomcat 5.5. The JSP files are in D:\Tomcat\webapps\cruisecontrol. However, the log files are in C:\logs. Because of the way cruisecontrol is configured I can link to the "C:\logs\project\cruisecontrol.log" using the relative path 'href="<%= artifacts_url %>/cruisecontrol.log', where artifacts_url="/logs/project/". I've tried to read that as a File object to then getAbsolutePath(), but haven't had any luck yet.

Is what I'm trying to do possible? Please let me know if I can be more clear in the asking of this question.

TIA, John
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

You're probably looking for getRealPath
[ July 31, 2007: Message edited by: Ben Souther ]

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
John Dunning
Greenhorn

Joined: Aug 31, 2004
Posts: 3
Thanks for the reply; unfortunately, that still gives me the path to the Tomcat installation directory plus the filename, even though that file is not there.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61420
    
  67

As your file is outside the purview of the web app, there is no way to automatically determine its path. You'll need to provide it. Rather than hard-coding it, consider using a context parameter or even a properties file.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16141
    
  21

To amplify on Bear's statement: A URL is not the same thing as a file path. They may look like file paths. They are often mapped to file paths. But they're not the same thing as file paths. A web server is not the same thing as a file server.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to get absolute path of linked resource outside of Tomcat