Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to load the resources outside WEB-INF?

 
subbukumararaja chandrasekaran
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • 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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64827
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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
Author and ninkuma
Marshal
Pie
Posts: 64827
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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.
 
dileep keely
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
,
 
subbukumararaja chandrasekaran
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic