You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Chris Bailey <ch...@codeintensity.com> on 2002/06/28 19:21:38 UTC

Question about context paths and IMG URL's

I seem to have confused myself about the proper way to specify an image
location in HTML that my servlet spits out.  If I have an "images" directory
at the "root" of my webapp, is it safe to always do this:

   <img src="/images/foo.gif">

Or, how does the context "path" attribute play into this?  We always set our
path to "" (our app is the only one running in the container).  But, I'm
wondering about this if we wish to make it a bit more generic so that we
could just give a customer a WAR file and let them set it up in their
container as they wish.

____
Chris Bailey       mailto:chris@codeintensity.com
Code Intensity       http://www.codeintensity.com


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Question about context paths and IMG URL's

Posted by Eric Everman <ev...@precedadesign.com>.
Using "/xxx/yyy" in HTML will cause problems if you are not in the default 
context because it will point directly to the host root.  I would almost 
say that an HTML relative reference starting with "/" is *always* wrong 
unless your working within a cooperative environment where you know what is 
at the server's root.

Personally, I always include a dynamic HTML Base tag in all pages that 
points to the current context root.  Thus, all relative URLs (not starting 
with a '/') point to the context base.  This is a bit of a pain when you 
want to point to a resource that is -right next to- the current page, but 
in the long run it makes things easier for included pages since all 
relative references start from the same base.

As an example, if you have a shared page that is @included (not 
jsp:include) in other pages, relative references in the included fragment 
would be relative to whatever page their used in, resulting in lots of 
broken img tags.  By consistently specifying a base, you can prevent this 
from happening.


Cheers,

Eric Everman



At 12:21 PM 6/28/2002, you wrote:
>I seem to have confused myself about the proper way to specify an image
>location in HTML that my servlet spits out.  If I have an "images" directory
>at the "root" of my webapp, is it safe to always do this:
>
>    <img src="/images/foo.gif">
>
>Or, how does the context "path" attribute play into this?  We always set our
>path to "" (our app is the only one running in the container).  But, I'm
>wondering about this if we wish to make it a bit more generic so that we
>could just give a customer a WAR file and let them set it up in their
>container as they wish.
>
>____
>Chris Bailey       mailto:chris@codeintensity.com
>Code Intensity       http://www.codeintensity.com
>
>
>--
>To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
>For additional commands, e-mail: <ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>