You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Mario Busche <Ma...@softm.de> on 2000/05/05 10:42:02 UTC

context maping

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???

bye
Mario Busche

Re: context maping

Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
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