• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

Relative directory issues

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic