NOTE: I sent this mail to the list last week, but it never got there, so
I'll resend. Apologies if you get this twice.

Hello Mike,

"/dispatch" is not an absolute URL. It needs a context to mean something
(like a protocol and a host).

However the leading slash implies that the path is relative to some
root. The question is whether this root should be the root of the entire
website, or the root of the web application. Considering that the
servlet 2.2 specification is application-centric and not site-centric,
the normal way to read it would be that the root is in fact the
application root and nothing else. This is also how we interpret the
specification. However, I do agree that the specification should clarify
this and we can of course have mis-interpreted what the specification
says.

Eduardo, if you are listening, can you clarify what the behaviour should
be?

In this case the root of the web-application is "http://myhost.com/cvg/"
and the path "/dispatch" should be mapped to
"http://myhost.com/cvg/dispatch". This is how paths are normally treated
in the servlet specification and to me, it seems to be the way that
makes most sense. Why?

Redirects are normally done within an application (if you design your
web application in the correct way). Since the application might be
placed anywhere, you can not hardcode the application location into your
servlets/JSPs. (Just
imagine how it would be if people started doing
sendRedirect("/~foo/bar/"). It would be horrible to move the
web-application. This means you would have to do
response.sendRedirect(request.getContextPath() + "/foo") in almost every
redirect.

Also, alot of applications that were developed before the introduction
of web-applications would break if paths were not handled like this. For
example, old applications might depend on that the servlet dir would
always be http://myhost/servlet/. Such an application might do a
sendRedirect("/servlet/foo") (of course, this wasn't legal per the 2.1
spec, but alot of engines broke the spec. In fact Orion handled this
according to the specification and people complained about it). Now, in
a Servlet 2.2 container, someone deploys the application under the
"http://myhost/myapp" path. The application wouldn't work unless the
path "/servlet/" maps to "http://myhost/myapp/servlet/".

One of the great things about web-applications is that every application
gets a context root and don't care about if they're located under the
actual site root, or under some directory mapping. Putting your
application under http://www.foo.com/ or under http://www.bar.com/baz/
shouldn't matter.

Again, Eduardo, are we thinking in the correct way?

Mike et al, if Eduardo doesn't see this, I'll mail him personally to ask
him to clarify.

Regards,
Karl Avedal
The Orion team

Mike McKechnie wrote:

> >
> > 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").
> >
>
> Orion was actually doing it wrong. "/dispatch" is an absolute path, what you
> want is just "dispatch".
>
> So,
>
> response.sendRedirect(response.encodeRedirectURL("dispatch"));
>
> will always take you from the current context to the current context plus
> "/dispatch", while
>
> response.sendRedirect(response.encodeRedirectURL("/dispatch"));
>
> will always take you to the page "/dispatch" on the same host and port as
> the current context.

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

Reply via email to