aspose file tools*
The moose likes Servlets and the fly likes How to load the resources outside WEB-INF? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to load the resources outside WEB-INF?" Watch "How to load the resources outside WEB-INF?" New topic
Author

How to load the resources outside WEB-INF?

subbukumararaja chandrasekaran
Greenhorn

Joined: Sep 24, 2010
Posts: 17
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

Joined: Jan 10, 2002
Posts: 61768
    
  67

You need to specify a file, not a folder. What are you going to do with a folder?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
subbukumararaja chandrasekaran
Greenhorn

Joined: Sep 24, 2010
Posts: 17
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

Joined: Jan 10, 2002
Posts: 61768
    
  67

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

Joined: Jun 28, 2010
Posts: 98
,
subbukumararaja chandrasekaran
Greenhorn

Joined: Sep 24, 2010
Posts: 17
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to load the resources outside WEB-INF?