| 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: 56153
|
|
|
You need to specify a file, not a folder. What are you going to do with a folder?
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About 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: 56153
|
|
|
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: 91
|
|
|
,
|
 |
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.
|
 |
 |
|
|
subject: How to load the resources outside WEB-INF?
|
|
|