• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Accessing File from ActionClass

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I need to access file which is above WEB-INF folder from my action class.
I dont want to specify the absolute path for this...
I even used URL url = new URL("http://localhost:7001/webapps/props/some.xml");
and "http://localhost:7001/" is also absolute ... can anyone tell me how to access the file ?

Thanks,
 
Ranch Hand
Posts: 341
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try something like,




This will get you the path and then do normal IO.
[ April 23, 2008: Message edited by: Anubhav Anand ]
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Files above WEB-INF are inaccessible through the web server interface. It's this way by design, so malicious visitors can't get the source of your pages or Java classes.
I usually put files I need access to in WEB-INF/classes and load them with Class.getResourceAsStream().
 
madhu Chitloore
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think files like propertyfiles , xmls , etc.. should be above WEB-INF ...
Not every such files will be placed inside WEB-INF ... Anyway it worked ..

Thank you
 
Anubhav Anand
Ranch Hand
Posts: 341
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by madhu cm:
I think files like propertyfiles , xmls , etc.. should be above WEB-INF ...
Not every such files will be placed inside WEB-INF ... Anyway it worked ..

Thank you



Indeed they ought to be outside the WEB-INF folder. The way I suggested will anyway work for any kind of location be it in or outside WEB-INF. Moreover, the files inside WEB-INF are not accessible through web server interface. That's *my* take.
reply
    Bookmark Topic Watch Topic
  • New Topic