File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Tomcat and the fly likes File path in Tomcat Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "File path in Tomcat" Watch "File path in Tomcat" New topic

File path in Tomcat

Hanna Habashy
Ranch Hand

Joined: Aug 20, 2003
Posts: 532
My image files are not displayed on my jsp pages. The container cannot read the relative path.

My app. name is : dice
My imge files are in: dice/images
my context path in server.xml is : /dice

In my jsp I have <img src="/images/home/question_mark.gif">
This .gif file cannot be displayed.
If I modify it to be <img src="/dice/images/home/question_mark.gif">
It works fine

What puzzling me this code works fine: <%@ include file="/doc/help.html" %>

Both the directive and the html code use relative paths. One works, and the other doesn't. How can I tell the container to look at the relative path of the application.



SCJD 1.4<br />SCJP 1.4<br />-----------------------------------<br />"With regard to excellence, it is not enough to know, but we must try to have and use it.<br />" Aristotle
Ilari Moilanen
Ranch Hand

Joined: Apr 15, 2008
Posts: 199
If I understand your problem correctly then both of these should work
<img src="/dice/images/home/question_mark.gif">
<img src="images/home/question_mark.gif">

the first one since it now points to the root (provided that the server is configured so that the image is located here http://domainname/dice/images/home/question_mark.gif)
and the second one since now you don't start at the root but from where you are currently located. This of course requires that the page that has the link is viewed to user at the root of "dice/".

Hope this helps.
Ben Souther

Joined: Dec 11, 2004
Posts: 13410


To learn the ins and outs of relative links in a server side Java app.

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Hanna Habashy
Ranch Hand

Joined: Aug 20, 2003
Posts: 532

Thank you
I agree. Here's the link:
subject: File path in Tomcat
It's not a secret anymore!