• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Accessing File from ActionClass

 
madhu Chitloore
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • 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,
 
Anubhav Anand
Ranch Hand
Posts: 341
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • 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 ]
 
Joe Ess
Bartender
Posts: 9312
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • 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
  • 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 Java Spring
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic