I agree, here's how I solved the problem. I moved server specific
functionality to a static method of my "ServletContainer" class, whose
behavior is configurable at run-time via a properties file:
# Set this to true if your servletContainer interprets the root of the
# request URL as relative to docroot, rather than to context root
# should be true for tomcat, false for orion (as of 7/17/00)
# default is false
sendRedirectUsesDocroot=false
It then contains this method:
/**
* Redirect the client browser to the specified URL.
*
* Some servers do not handled relative paths the same. Some
* make the request relative to docroot, others the context root.
* This method is sensitive to the property
* <code>sendRedirectUsesDocroot</code>, which should be set to
* true or false.
*
* @param req the request
* @param res the response
* @param href the url to redirect to (before any conversion)
**/
static public void sendRedirect(HttpServletRequest req,
HttpServletResponse res, String href)
throws IOException {
if (ServletContainer.sendRedirectUsesDocroot() && href.startsWith("/"))
href = req.getContextPath() + href;
Debug.println("Redirecting to " + href);
res.sendRedirect(href);
}
All my code (taglibs, servlets, etc) that needs this functionality defers it
to this class.
--
Duane Fields
[EMAIL PROTECTED]
Managing Engineer, Web Development
(512) 744-1012
----- Original Message -----
From: ""Christian Sell"" <[EMAIL PROTECTED]>
Newsgroups: uo.listserv.orion
Sent: Saturday, July 15, 2000 7:15 AM
Subject: Re: sendRedirect in orion and jrun
> >First let me start by saying that this is not a bug...nor a
> >misinterpretation of the specs.
>
> the specs are so unclear on this one that it is hard to misinterpret them
> anyway. Magnus already conceded that the issue was officially still "up in
> the air". But I agree (as I said previously) that context-relative makes
the
> most sense, for the very reasons that you cite. My current problem is how
to
> write server-portable code (and deployment descriptors!) which in the case
> of sendRedirect leads me to having to use hard-coded absolute URLs, as you
> describe.
>
> >Servlets 2.2 specification introduces the
> >concept of "web-app" contexts.
>
> well, I guess that is not news anymore.. ;-)
>
> > String requestURL=HttpUtils.getRequestURL(request).toString();
> > String absolute=requestURL.substring(0,
> > requestURL.length()-request.getRequestURI().length());
> > response.sendRedirect(absolute+"/myothercontext/index.jsp");
>
> thanks. I was just going to roll up my sleeves to write that one. Funny
> though that I have to do this to redirect into my own context (due to
server
> incompatibility, not orions fault).
>