I am trying to understand the behavior of sendRedirect(). The ServletThat is a root-relative URL; the correct URL handling (see RFC's) results in A, so Tomcat is right, and WebSphere is probably trying to be helpful, but is wrong.
Spec states:The sendRedirect method will set the appropriate headers and content
body to direct the
client to a different URL. 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. If a partial URL is given and, for whatever reason,
cannot be converted into a valid
URL, then this method must throw an IllegalArgumentException.What I find somewhat ambiguous is the line "the underlying container
must translate the relative path to a fully qualified URL". Does this
the container should insert the context path in the URL? That is,
suppose I have an application whose root is /Test. In my code, I do the
following:response.sendRedirect("/ReallyATest");
Should the address sent to the client be:
A) http://myserver/ReallyATest
B) http://myserver/Test/ReallyATest
The correct solution for what you want is to use a completely relative URL, i.e. response.sendRedirect("ReallyATest"); which will probably work on both appserver packages.
BTW, most browsers will gracefully handle a redirect to a relative URL, and interpret it in the logical way, even though it's bad HTTP.
It seems that Apache follows A. It does not insert the context path.
However, I am also using IBM WebSphere 3.5 and it does B! So, which is
the right one?For now, I will use the following work around for portability:
response.sendRedirect(request.getRemoteHost() + request.getContextPath()
+ "ReallyATest");Thanks,
Paolo
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]
-- David Crooke, Chief Technology Officer Convio Inc. - the online partner for nonprofits 4801 Plaza on the Lake, Suite 1500, Austin TX 78746 Tel: (512) 652 2600 - Fax: (512) 652 2699