File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes Relative directory issues Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Relative directory issues" Watch "Relative directory issues" New topic

Relative directory issues

Dave Berkheimer

Joined: Feb 05, 2001
Posts: 26
Hi All,

I've got a bit of a problem that someone out there might be able to help me with. I'm trying to read the contents of a directory relative to the location of a JSP page. Let me give you the specifics.

I have a project on my local machine. The project is located in the "c:/public_html" directory. I'm trying to read files in the "c:/public_html/jpegs/standard/" directory. Now on my local machine this all runs like a champ using the following code in a JSP located in the "c:/public_html" directory.

Now here's where the problem comes in. When I move this code to my hosting service I get a Null pointer error from the dir variable when using list(). It appears that getContextPath is returning a null value. What I'm attempting to do is write my code in such a way that I don't have to make any changes going from my local test environment to my production environment on my hosting service. Any suggestions or ideas?


Sun Certified Java Programmer
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63866

Have you looked at the string created when you use the context path? Does it form a valid file system path? (Answer is, of course, no).

The context path is part of the web address, and has nothing to do with the file system.

Unless you are running the web app out of a war file (looks like not), you should investigate the use of ServletContext.getRealPath().

[Asking smart questions] [About Bear] [Books by Bear]
Dave Berkheimer

Joined: Feb 05, 2001
Posts: 26
Thanks Bear,

Your suggestion did THE trick..... take a couple beers out of petty cash.

Who was that masked man?

I agree. Here's the link:
subject: Relative directory issues
jQuery in Action, 3rd edition