Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Relative directory issues

 
Dave Berkheimer
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64967
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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().
 
Dave Berkheimer
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bear,

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

Who was that masked man?

Dave
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic