JonTom Kittredge wrote:
>
> I've been trying out my web-app on different Servlet engines and have
> found a discrepancy between the way response.sendRedirect() works on
> Orion 0.9 beta versus JRun 3.0 beta. Orion behaved the way I expected,
> but when I tried to find out from the Servlet 2.2 spec the way this
> situation should be handled, I didn't find a clear answer.
>
> Briefly, in my servlet, when I expected response.sendRedirect() to
> interpret relative URLs as being relative to the servlet-context. This
> is what Orion is doing, however JRun interprets them as relative to the
> document root.
>
> For instance, my web-app has a context path of "/cvg" and the servlet I
> want to redirect to is mapped to "/dispatch". If I call
> response.sendRedirect("/dispatch") on Orion, it translates the redirect
> to "http://myhost/cvg/dispatch", however, on JRun, it translates it to
> "http://myhost/dispatch". To get the result I want on JRun, I have to
> make my call as response.sendredirect(request.getContextPath() +
> "/dispatch").
>
> The spec says about sendRedirect (Section 6.3) that, "It is legal to
> call this method with a relative URL path, however the
> underlying container must translate the relative path to a fully
> qualified URL for transmission back to the client." I haven't found
> anywhere in the actual spec where it specifies exactly what "relative
> path" would mean in this context, but relative to the contextPath is the
> most reasonable interpretation as see it.
>
> Can anyone shed light on this?
My take on this is that a "relative path" here means a path that doesn't
start with a slash, such as "dispatch", and that it should be interpreted
as relative to the current URL. The reason is that this is how a browser
resolves a relative path, e.g. in an HTML reference or in a Location header
(which is what sendRedirect actually sends to the client, together with a
3xx status code). The contextPath shouldn't play a role here, IMHO.
The reason the requirement for translation was added to the spec was that
the HTTP spec doesn't allow relative paths in the Location header, even
though most (all?) modern browsers handle them. Since it's common that
servlets still use relative paths in sendRedirect(), it was decided that
the container should make sure it was converted to a valid path instead
of just saying that a relative path was not supported (as it did before 2.2).
So in your example, with "/dispatch", the Location header should always be
set to "http://myhost/dispatch", since you use an absolute path as the
argument. But if you instead use "dispatch" as the argument in a servlet
invoked with the URL "/cvg/foo", it should be set to
"http://myhost/cvg/dispatch".
Hans
--
Hans Bergsten [EMAIL PROTECTED]
Gefion Software http://www.gefionsoftware.com
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets