Hi, same problem that lots of people have/are having but can't find a
solution.
I have .war file with hierarchy /WEB-INF/images/testimage.gif
The images aren't being displayed in the webpage along with all the
other content (from /WEB-INF/jsp/*). But, they also aren't being
displayed in a browser! The URL I enter for the webpage that displays
is
http://localhost:8080/testapp/index.jsp
The URL's I enter for the image that doesn't display is
http://localhost:8080/testapp/../images/testimage.gif
or
http://localhost:8080/testapp/images/testimage.gif
or
http://localhost:8080/testapp/WEB-INF/testimage.gif
or
http://localhost:8080/testapp/WEB-INF/images/testimage.gif
I'm desperate. What should I try?
testimage.gif exists in the WAR file with location
/WEB-INF/images/testimage.gif
Thank you
Barry
Moiristo - 06 Jul 2006 18:47 GMT
> Hi, same problem that lots of people have/are having but can't find a
> solution.
[quoted text clipped - 22 lines]
> testimage.gif exists in the WAR file with location
> /WEB-INF/images/testimage.gif
Why do you insist on storing the images/jsp in the WEB-INF directory?
Thomas Hawtin - 06 Jul 2006 19:18 GMT
> Hi, same problem that lots of people have/are having but can't find a
> solution.
[quoted text clipped - 5 lines]
> displayed in a browser! The URL I enter for the webpage that displays
> is
Files within /WEB-INF/ (and /META-INF/) will not be directly served to
an HTTP request. This prevents access to your code and configuration.
Usually what you have is a front (or fat) controller servlet that
handles the request and forwards onto the view part of the code in a JSP
within /WEB-INF/. You should take care not to allow the servlet to just
forward to anything within /WEB-INF/. If you just want a file to be
returned to the browser as is, without intervention of a front
controller, don't put it in /WEB-INF/.
Tom Hawtin

Signature
Unemployed English Java programmer
http://jroller.com/page/tackline/
Juha Laiho - 09 Jul 2006 18:53 GMT
bbulsara23@hotmail.com said:
>Hi, same problem that lots of people have/are having but can't find a
>solution.
>
>I have .war file with hierarchy /WEB-INF/images/testimage.gif
As Moiristo already commented, by placing something under /WEB-INF/
you are prohibiting any direct browser access to the file. Either:
- write a servlet to handle all access to f.ex. /images/*, and
have the servlet parse the request and return an appropriate image
(however, if the images are static files to begin with, I don't
see any value for this)
- move the /images/ directory to top level of your application (so,
to the same level with /WEB-INF/, not to underneath /WEB-INF/),
and access them as http://server:port/application/images/img.gif
Then, if you really need to have your servlets load resources from
wihtin /WEB-INF/ (so, you need some data visible to your servlets,
but not directly downloadable by any browser or other web client),
then use ServletContext.getResource() or
ServletContext.getResourceAsStream() .

Signature
Wolf a.k.a. Juha Laiho Espoo, Finland
(GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V
PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++
"...cancel my subscription to the resurrection!" (Jim Morrison)