This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes Servlets and the fly likes How to access gif files from servelets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to access gif files from servelets" Watch "How to access gif files from servelets" New topic

How to access gif files from servelets

Ben Field

Joined: Mar 09, 2004
Posts: 11

I need my servelet to use a GIF file. I have tried placing he gif file in the following locations:

c:\Tomcat 4.0\
c:\Tomcat 4.0\webapps
c:\Tomcat 4.0\webapps\myapp\
c:\Tomcat 4.0\webapps\myapp\classes

And I have tried refering to the gif in the following manner:
out.println("<IMG SRC=tick.gif'></TD>");
out.println("<IMG SRC=/tick.gif'></TD>");
out.println("<IMG SRC='myapp/tick.gif'></TD>");
out.println("<IMG SRC='/myapp/tick.gif'></TD>");

Do I have to specify the exact path?

Charles Lyons
Ranch Hand

Joined: Mar 27, 2003
Posts: 836
You should deploy the image file to somewhere in the public part of your application (in the case of Tomcat, this is some path under the docBase which isn't /WEB-INF/).

You then need to use a link which corresponds to the location of the file as seen by a browser. It's difficult to say much more without knowing where you publicly want the image to be accessible from, and how your domain is configured. It might be a good idea to use the opening / (absolute path) or it might not be (relative path), it depends on what you're trying to do.

More information would be helpful - for example, what URL are you currently accessing the application via?

Charles Lyons (SCJP 1.4, April 2003; SCJP 5, Dec 2006; SCWCD 1.4b, April 2004)
Author of OCEJWCD Study Companion for Oracle Exam 1Z0-899 (ISBN 0955160340 / Amazon Amazon UK )
Darren Edwards
Ranch Hand

Joined: Aug 17, 2005
Posts: 69

Should work assuming you are accessing your application with a URL such as
I agree. Here's the link:
subject: How to access gif files from servelets
It's not a secret anymore!