On Sun, 11 Mar 2001, James Cook wrote:
> Craig,
>
> Forwards and redirects not withstanding, is it a fair statement to conclude
> that all links (hrefs, image srcs, etc.) in a web application must be
> rendered in a relative manner?
>
Unfortunately, we could not make such a rule even if we wanted to.
> There isn't any talk of making <img src="/images/a.gif"> relative to a
> context is there?
>
No, but it's not because this would not be desireable for servlet apps
:-).
The problem is that paths in an <img> or <a> tag are interpreted by the
*browser*, not by the server. The path "/images/a.gif" is going to be
interpreted as being relative to the document root of the server, not the
context root of the application. Browsers have no clue what a web
application is.
Struts tries to help you deal with this unpleasantness by including the
"page" attribute on the <html:link> and <html:image> tags, which both
accept a context relative path. They both convert this path to be
relative to the server's document root before sending to the browser, so
you can at least pretend your links are all context-relative. So, you can
safely use:
<html:image page="/images/a.gif"/>
and it will get converted to (assuming "/myapp" is your context path):
<img src="/myapp/images/a.gif">
which will work as you expect.
> jim
>
Craig