wood burning stoves 2.0*
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
Author

Relative directory issues

Dave Berkheimer
Greenhorn

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?

Thanks
Dave


Sun Certified Java Programmer
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60053
    
  65

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] [Bear's FrontMan] [About Bear] [Books by Bear]
Dave Berkheimer
Greenhorn

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?

Dave
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Relative directory issues
 
Similar Threads
Tomcat 5 on hosting service
ServerletException - access denied
Permission denied exception on saving file to filesystem
Unable to parse setupCmdLine: null\bin\setupCmdLine.bat
configuration file path