tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <>
Subject Re: context maping
Date Fri, 05 May 2000 16:55:29 GMT
Mario Busche wrote:

> Hello all,
> i have a simple question acording to context maping.
> In the server.xml i have a context defenition like
>    <Context path="/demo" docBase="share/htdocs/demo" debug="9"
> reloadable="true" >
>     </Context>
> in the dir share/htdocs/demo i have an index.jsp with an frame.
> the urls in the frame all starts with an "/" which is acording to the
> pdf specification relative to the context defenition in the server.xml
> but tomcat searches for the html pages relative to the root-path "".
> is this an bug or have i misunderstood the specification???

You've hit one of the places where it is *definitely* confusing.  :-)

The key issue when resolving relative or absolute URIs is to remember who is
doing the resolving.  When you include a hyperlink in a web page, it is the
*browser* that resolves this URI (against the URI of the page containing the
link).  So if you include something like this in an HTML page (references to
frame contents would work the same way):

    <a href="/menu.jsp">Go to the menu</a>

then the browser interprets that slash as "relative to the server's document
root" and sends in a request for "/menu.jsp", instead of "/demo/menu.jsp".

The way to deal with it is to use relative URIs (no leading slash) in your
hyperlinks, but use context-relative URIs  (leading slash) when you use
RequestDispatcher.forward/include or the <jsp:forward> and <jsp:include>
elements.  So, your hyperlink should say:

    <a href="menu.jsp">Go to the menu</a>

instead, and it will go the right place.

> bye
> Mario Busche

Craig McClanahan

View raw message