The easiest way to understand this is to think about how a browser sees a 
relative link.  Browsers don't know that they're dealing with a servlet app. 
A sendRedirect simply puts the following header in the response:
"Location:  url" 

Let's take the following url:
http://www.mydomain.com/cal/index.jsp

If your page "index.jsp" resides in the context root "cal" and you want to 
send a redirect to "page2.jsp"  you would use "page2.jsp".  This tells the 
browser to look in the current directory for a file name "page2.jsp". 

If you enter "/page2.jsp"  The browser will go to what IT considers to be the 
webroot;  the first directory after the base url "http://www.mydomain.com/"; 
and look for "page2.jsp". 

If you're several directories below the context root and need to redirect to a 
higher directory, you're better off prepending one "../" to the url for each 
directory that you need to climb than to try to list the context root and 
work your way down (" /cal/page.jsp").  This way, you won't need to fish 
through your code and change the urls if the application name "cal" changes. 
But that's just my opinion.

-Ben

On Friday 05 September 2003 02:07 pm, Charlie Toohey wrote:
> The Servlet API doc for the sendRedirect method states:
>
> "....If the location is relative with a leading '/' the container
> interprets it as relative to the servlet container root....."
>
> I've looked thru the Servlet Spec and can not quite figure out what they
> mean by servlet container root ? Is this a typo and supposed to be servlet
> context root ? Or is there really such a thing as the servlet container
> root, and if so, what is it ?
>
> e.g. if my context path is "/cal" and I want to redirect to
> "/cal/form/index.jsp", what would I use in sendRedirect ?
> (I know I could do a forward, but want to redirect in my situation)
>
> Thanks,
> Charlie
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to