Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / July 2006

Tip: Looking for answers? Try searching our database.

displaying images in war files

Thread view: 
bbulsara23@hotmail.com - 06 Jul 2006 15:03 GMT
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)



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.