Hi Wyn
Yes, that's what I'm trying to do. My problem is that the uri is not fixed;
it could belong to any of the other web apps, including the default /
handler. Now getContext() gets the right ServletContext fine, but to then
get a RequestDispatcher, I need to strip off the context root part of the
URI, and I don't know what that is! In the exanple here, it is "/app2" but
for the root context it would be just "/". What I need is a ServletContext
method which returns the context string, but I don't think such a method
exists.
Richard
> -----Original Message-----
> From: Wyn Easton [mailto:[EMAIL PROTECTED]]
> Sent: 13 November 2000 22:51
> To: [EMAIL PROTECTED]
> Subject: Re: Contexts and dispatchers
>
>
> Hi Richard,
>
> Sorry for the misunderstanding. I think I finally see what you are
> trying to do.
>
> Suppose you have two web apps app1 and app2.
> You are in a servlet in app1 and you want a RequestDispatcher
> for a JSP (say my.jsp) in app2. You would:
>
> RequestDispatcher rd;
> String uri = "/app2/my.jsp";
> ServletContext ctxt =getServletContext().getContext(uri);
> rd=ctxt.getRequestDispatcher("/app2.jsp");
> if (rd != null)
> rd.include(request,response);
>
> "ctxt" is the Servlet Context of app2, so you don't need
> to strip or add anything.
>
> Are we getting any closer?
>
>
>
>
>
>
>
>
> --- Richard Evans <[EMAIL PROTECTED]> wrote:
> > >
> > > There are two getRequestDispatcher() methods.
> > > One in the ServletContext that uses absolute paths
> (start with /).
> > > One in the request that uses relative paths.
> > > Looks like you need the absolute path one.
> >
> > No. My understanding is that the one in ServletContext takes paths
> > relative to
> > the context root. _Not_ absolute paths.
> >
> > To recap ..
> >
> > I have a URI which I need to forward to the correct ServletContext.
> > I can
> > do something like:
> >
> > ServletContext other = getServletContext().getContext(uri);
> >
> > This works because getContext() takes absolute paths.
> >
> > But then how to I call getRequestDispatcher or getRealPath on that
> > other
> > context? To get the correct result I need to strip off the other
> > contexts root
> > from the URI before callign getRequestDispatcher or
> getRealPath. But
> > I can't
> > find any way of determining what the root of the other context is.
> > It could
> > just be the default "/" context or it could be a context which
> > handles the URL
> > explicitly.
> >
> > Help, anyone?
> >
> > Richard
> >
> > >
> > > --- Richard Evans <[EMAIL PROTECTED]> wrote:
> > > > But I need the context path for a different ServletContext.
> > > > request.getContextPath returns the path for _this_ context, not
> > a
> > > > foreign
> > > > one.
> > > >
> > > > > -----Original Message-----
> > > > > From: Wyn Easton [mailto:[EMAIL PROTECTED]]
> > > > > Sent: 11 November 2000 21:57
> > > > > To: [EMAIL PROTECTED]
> > > > > Subject: Re: Contexts and dispatchers
> > > > >
> > > > >
> > > > > --- Richard Evans <[EMAIL PROTECTED]> wrote:
> > > > > > "/file/x/y". (The URL without the context root). How to I
> > find
> > > > the
> > > > > > context
> > > > >
> > > > > Use request.getContextPath()
> > > > >
> > > > > If your web app. is called app1 getContextPath() would return
> > /app1
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > =====
> > > > > Wyn Easton
> > > > > [EMAIL PROTECTED]
> > > > >
> > > > > __________________________________________________
> > > > > Do You Yahoo!?
> > > > > Yahoo! Calendar - Get organized for the holidays!
> > > > > http://calendar.yahoo.com/
> > > >
> > >
> > >
> > > =====
> > > Wyn Easton
> > > [EMAIL PROTECTED]
> > >
> > > __________________________________________________
> > > Do You Yahoo!?
> > > Yahoo! Calendar - Get organized for the holidays!
> > > http://calendar.yahoo.com/
> > >
>
>
> =====
> Wyn Easton
> [EMAIL PROTECTED]
>
> __________________________________________________
> Do You Yahoo!?
> Yahoo! Calendar - Get organized for the holidays!
> http://calendar.yahoo.com/