tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ben Souther <>
Subject Re: response.sendRedirect
Date Fri, 05 Sep 2003 19:25:53 GMT
>The one thing you want to watch out for with relative redirects is that 
>they're converted by the servlet container to absolute URLs (this is in the 
>servlet spec).  This is, by the letter of the HTTP spec, the correct thing 
>to do.  Unfortunately, it can cause problems in deployments where an 
>proxying SSL accelerator is used.  These are proxies that take HTTPS 
>requests and convert them to HTTP requests, handling all the SSL crypto 
>stuff in the process (this technique is used in some high-volume deployments 
>where SSL is required...the SSL stuff can be done in hardware).

I stand corrected. I was unaware the container converted relative urls to 
absolute urls.  That being said, the rest of what I've said still holds true, 
just not for the reason that I thought it does.

On Friday 05 September 2003 02:53 pm, Ben Souther wrote:
> 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:
> 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
> "" 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:
> > For additional commands, e-mail:
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:

Ben Souther
F.W. Davison & Company, Inc.

September 18-19, 2003 in Boston/Brookline, MA
Additional Training Sessions held September 17, 2003
More info >>

View raw message