You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Russell Freeman <Ru...@sagemaker.com> on 2000/11/30 17:12:45 UTC

hrefs in documents and sendRedirect()

To restate a so far unresolved problem,

Do I need to include the name of my context in all hyperlinks, e.g. if my
context is /foo, then a link will be <a href="/foo/index.html">, my
stylesheet will be in "/foo/styles.css" etc. 

So far things only work if I add the context prefix but not for
sendRedirect(), which seems to not need it? 

Confused,
Russ


Re: hrefs in documents and sendRedirect()

Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
Russell Freeman wrote:

> To restate a so far unresolved problem,
>
> Do I need to include the name of my context in all hyperlinks, e.g. if my
> context is /foo, then a link will be <a href="/foo/index.html">, my
> stylesheet will be in "/foo/styles.css" etc.
>

If you are creating hyperlinks that start with "/" then you *do* need the
context path added on the front.  This is because the browser will interpret
such a URL as being relative to the server's document root.

If you use relative URLs, though (not starting with "/"), then you do *not* want
to add the context path.  For example, if you have a page "index.html" that
wants to create a link to a page "display.html" in the same directory, simply
write:

    <a href="display.html">The Display Page</a>

>
> So far things only work if I add the context prefix but not for
> sendRedirect(), which seems to not need it?
>

response.sendRedirect() converts relative URLs back to absolute ones (adding the
content path for you).  This behavior is required by the servlet specification,
although not every servlet container actually does it.

>
> Confused,
> Russ

Craig McClanahan



Re: hrefs in documents and sendRedirect()

Posted by Dave Smith <sa...@home.com>.
Russell,

In order to use

response.sendRedirect("/somepage.html");

you need to be working in the root context. Out of the box, this means
document path webapps/Root/somepage.html
(at least for tomcat 3.1).

If you make your own context, you will need /contextname/somepage.html,
which will translate to webapps/contextname/somepage.html. All of that stuff
is configurable. Please study server.xml to figure
out how.


Good luck,

Dave

----- Original Message -----
From: "Russell Freeman" <Ru...@sagemaker.com>
To: <to...@jakarta.apache.org>
Sent: Thursday, November 30, 2000 10:12 AM
Subject: hrefs in documents and sendRedirect()


> To restate a so far unresolved problem,
>
> Do I need to include the name of my context in all hyperlinks, e.g. if my
> context is /foo, then a link will be <a href="/foo/index.html">, my
> stylesheet will be in "/foo/styles.css" etc.
>
> So far things only work if I add the context prefix but not for
> sendRedirect(), which seems to not need it?
>
> Confused,
> Russ
>