Win a copy of GANs in ActionE this week in the AI forum
or WebAssembly in Action in the JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

Accessing File from ActionClass

 
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,
 
Ranch Hand
Posts: 341
Firefox Browser Spring Java
  • 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 ]
 
Bartender
Posts: 9612
16
Mac OS X Linux 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 Spring Java
  • 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.
 
Hey, sticks and stones baby. And maybe a wee mention of my stuff:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!