displaying images in war files

B

bbulsara23

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
 
M

Moiristo

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

Why do you insist on storing the images/jsp in the WEB-INF directory?
 
T

Thomas Hawtin

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

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
 
J

Juha Laiho

(e-mail address removed) 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() .
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,588
Members
45,095
Latest member
EmiliaAlfo

Latest Threads

Top