You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Lionel Farbos <li...@free.fr> on 2005/03/03 15:50:26 UTC
Re: RequestDispatcher.forward: SOLVED
Thanks to Tim and Remy for the answers;
For more explanations for those who have the same problem like me :
- see bugs 23211 and 33831 on http://issues.apache.org/bugzilla/
- In my example,
after ctx = ctx.getContext("/myNewContext");
but before dispatcher = ctx.getRequestDispatcher("/myNewServlet");
I can verify if my context (ctx) is the good one (or the context root) thanks to :
ctx.getServletContextName() //if servlet API is 2.4
or ctx.getInitParameterNames() return a initParameter present in my desired Context
or ctx.getAttributeNames() return an attribute present in my desired Context
or ctx.getRealPath("/myNewServlet") is a Path valid for my desired Context
On Wed, 2 Mar 2005 16:34:42 +0100
Lionel Farbos <li...@free.fr> wrote:
> Yes : it's my problem.
>
> ctx.getContext("/myNewContext") always return a Context (even if myNewContext is not deployed :-(
> and
> ctx.getRequestDispatcher("/myNewServlet") always return a dispatcher (even if myNewServlet is not here :-(
>
> So How can I avoid a 404 ?
>
> On Wed, 02 Mar 2005 10:24:37 -0500
> Tim Funk <fu...@joedog.org> wrote:
>
> > getRequestDispatcher() will always return a servlet. (The default servlet)
> >
> > -Tim
> >
> > Lionel Farbos wrote:
> >
> > > Hi,
> > > (I work on Tomcat 5.0.30).
> > >
> > > When my servlet (http://myVhost/proxy/testProxy) forward to another servlet :
> > > try {
> > > ServletContext ctx = getServletContext();
> > > ctx = ctx.getContext("/myNewContext");
> > > RequestDispatcher dispatcher = ctx.getRequestDispatcher("/myNewServlet");
> > > dispatcher.forward(request, response);
> > > } catch (Exception e) {e.printStackTrace();}
> > >
> > > (in server.xml, in the Context /proxy of myVhost, I put crossContext="true")
> > >
> > > If the Context /myNewContext is deployed in myVhost, the HTTPresponse is :
> > > HTTP/1.1 200 OK
> > > ...
> > > response of myNewServlet
> > >
> > > If the Context /myNewContext is not deployed, the HTTPresponse is :
> > > HTTP/1.1 404 /myNewServlet
> > > :-(
> > >
> > >
> > > 1) In other servlets containers, I read that ctx.getRequestDispatcher(...) returns null if the resource is absent.
> > > So, Why Tomcat reacts differently ? Is it a bug ?
> > >
> > > 2) In my case, I'd want to forward to myNewServlet if it is present, BUT, if it is absent, I'd want to call another url distant (with httpclient)...
> > > How can I do this with Tomcat ?
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org