• 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

How to load the resources outside WEB-INF?

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a situation where i need to read a directory which is sitting outside the WEB-INF directory.

How can read that directory as a resource using getResource()?

I guess, we can load only the resources that resides in WEB-INF, using getResponse.

If so, how shall i meet my requirement?

directory structure:
drwxr-xr-x 4 myself myself 304 2011-09-13 17:07 WEB-INF
drwxr-xr-x 2 myself myself 336 2011-09-13 17:07 calendar
drwxr-xr-x 2 myself myself 160 2011-09-13 17:07 css
drwxr-xr-x 2 myself myself 80 2011-09-13 17:07 html
drwxr-xr-x 2 myself myself 1992 2011-09-13 17:07 images

I like to load the images directory as a resource.
URL fileUrl = getServletContext().getResource("html/");

this not returning the actual directory path.
Its returning "jndi:/localhost/application_dir/html"

i am expecting the URL as /opt/tomcat/severs/servername/App/application_dir/html

How to get that value?

Environment: Eclipse + Tomcat6.0

thanks in advance.
 
Sheriff
Posts: 67746
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
You need to specify a file, not a folder. What are you going to do with a folder?
 
subbukumararaja chandrasekaran
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am going to get all the files under the directory "html".
In fact, in web sphere i am able to get that value.
But in tomcat the same code is not working.
 
Bear Bibeault
Sheriff
Posts: 67746
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
Assuming that you are not running out of an unexploded war, you can use getRealPath() and then use normal Java file I/O.
 
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
,
 
subbukumararaja chandrasekaran
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was not able to get the file as a resource, but when i try to get the servlet real path, i was able to reach the same directory hierarchy level.

From there i picked up the file using the relative path.

thanks a lot to those who has helped.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic