----- Original Message -----
From: "Jari Worsley" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, July 03, 2001 1:23 PM
Subject: Re: Help :: Problem testing Servlet methods that forward to JSPs


> Vincent Massol wrote:
> >
> > Note 1 : From the Servlet 2.2 API :
> >
> > " [...]
> > To allow RequestDispatcher objects to be obtained using relative paths,
> > paths which are not
> >
> > relative to the root of the ServletContext but instead are relative to
the
> > path of the current
> >
> > request, the following method is provided in the ServletRequest
interface:
> >
> > . getRequestDispatcher
> >
> > The behavior of this method is similar to the method of the same name in
the
> > ServletContext,
> >
> > however it does not require a complete path within the context to be
given
> > as part of the argument to
> >
> > operate. The servlet container can use the information in the request
object
> > to transform the given
> >
> > relative path to a complete path. For example, in a context rooted at
'/', a
> > request to
> >
> > /garden/tools.html, a request dispatcher obtained via
> >
> > ServletRequest.getRequestDispatcher("header.html") will behave exactly
like
> >
> > a call to ServletContext.getRequestDispatcher("/garden/header.html").
>
>
> So presumably this means we would need to take into account the
> ServletURL that a test case thinks it is running from? otherwise calls
> to getRequestDispatcher on a request may not work as intended - as won't
> they then all be relative to the redirector servlet at
> /test/ServletRedirector?
>

You are right of course ! I had read a bit too quickly the specs ... So what
I have put int CVS works if you put absolute paths. For relative paths, yes,
we'll have to take into account the setURL() ... I suggest that everyone
uses absolute paths, relative one are evil ! ... :-)
The only I can see to implement is by transforming a relative path (i.e. a
path that does not start by "/") into an absolute one, like this :

if (does not start with "/") then
  fullpath = getContextPath() + getServletPath() + "<relative path
provided>"
else
  fullpath = <relative path provided>
fi
return new RequestDispatcherWrapper(
    m_Request.getRequestDispatcher(fullpath));


> > Note 2 : We'll also need to provide support for getNamedDispatcher()
method
> > ...
>
> Hmmm, the change ends up being more complicated than at first it
> seems...  isn't that always the case?  ;)
>

after checking, getNamedDispatcher() was already supported ... ! I had
forgotten it ... :)

>
> Jari
> --
> Jari Worsley
> Senior Programmer
> Hyperlink Interactive Ltd
>

Reply via email to