You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by "Velmurugan (Java Team)" <we...@nallisoft.com> on 2003/04/04 08:35:14 UTC

Re: does the getRequestDispatcher().forward() method return control?

Hi,

I think this is a bug as per the servlet specification.Just check with some
other servlet engine. I will forward this error to tomcat developer list. I
was tested with Tomcat3.2.2.

Velmurugan P.
Java Team.

----- Original Message -----
From: "Hans Schippers" <sa...@PANDORA.BE>
To: <EJ...@JAVA.SUN.COM>
Sent: Thursday, April 03, 2003 1:44 AM
Subject: does the getRequestDispatcher().forward() method return control?


> Hi,
>
> if in a servlet, I have some code like:
>
> getServletConfig().getRequestDispatcher("/my/page.jsp").forward(request,
> response)
>
> Is it supposed to return control to the servlet afterwards?
>
> >From what I find on the net, it isn't, but when I try to print something
> to System.out after the forward call, that works...
>
> So did I misread on the www, or is this some bug in my webserver?
>
> I'm using JBoss/Tomcat btw...
>
> Thanks,
>
> Hans
>
>
===========================================================================
> To unsubscribe, send email to listserv@java.sun.com and include in the
body
> of the message "signoff EJB-INTEREST".  For general help, send email to
> listserv@java.sun.com and include in the body of the message "help".
>



---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: does the getRequestDispatcher().forward() method return control?

Posted by Rodrigo Ruiz <rr...@gridsystems.com>.
AFAIK, the only way in java to get what you ask for, is to raise an
Exception at the end of the forward() method.
Even doing so, you could wrap the forward() call in a try / catch block,
avoiding whatever mechanism the servlet engine
could use to get the desired behaviour.

Thespecification says that no ouput must be commited from the calling
servlet *before* the
forward() call, but says nothing about conditions after the call (Servlet
2.3 Spec. SRV 8.4).

If normal control flow should be broken after the call, I think the Java
Team would be in great problems ;-)

> Hi,
>
> I think this is a bug as per the servlet specification.Just check with
some
> other servlet engine. I will forward this error to tomcat developer list.
I
> was tested with Tomcat3.2.2.
>
> Velmurugan P.
> Java Team.
>
> > Hi,
> >
> > if in a servlet, I have some code like:
> >
> > getServletConfig().getRequestDispatcher("/my/page.jsp").forward(request,
> > response)
> >
> > Is it supposed to return control to the servlet afterwards?
> >
> > >From what I find on the net, it isn't, but when I try to print
something
> > to System.out after the forward call, that works...
> >
> > So did I misread on the www, or is this some bug in my webserver?
> >
> > I'm using JBoss/Tomcat btw...
> >
> > Thanks,
> >
> > Hans
> >


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: does the getRequestDispatcher().forward() method return control?

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Fri, 4 Apr 2003, Velmurugan (Java Team) wrote:

> Date: Fri, 4 Apr 2003 12:05:14 +0530
> From: "Velmurugan (Java Team)" <we...@nallisoft.com>
> Reply-To: Tomcat Users List <to...@jakarta.apache.org>
> To: Hans Schippers <sa...@PANDORA.BE>
> Cc: tomcat-user@jakarta.apache.org
> Subject: Re:      does the getRequestDispatcher().forward() method return
>     control?
>
> Hi,
>
> I think this is a bug as per the servlet specification.Just check with some
> other servlet engine. I will forward this error to tomcat developer list. I
> was tested with Tomcat3.2.2.
>
> Velmurugan P.
> Java Team.
>
> ----- Original Message -----
> From: "Hans Schippers" <sa...@PANDORA.BE>
> To: <EJ...@JAVA.SUN.COM>
> Sent: Thursday, April 03, 2003 1:44 AM
> Subject: does the getRequestDispatcher().forward() method return control?
>
>
> > Hi,
> >
> > if in a servlet, I have some code like:
> >
> > getServletConfig().getRequestDispatcher("/my/page.jsp").forward(request,
> > response)
> >
> > Is it supposed to return control to the servlet afterwards?
> >

A call to RequestDispatcher.forward() is just like any other Java method
-- there is no magic here.

Control is indeed returned to the line after this line once it completes.
Java doesn't have anything like a longjmp() in C, so the only other
possibility would be that the code inside the forwarded-to servlet threw
an exception -- but your code above would still have a chance to catch
that if you put it inside a try/catch block.

> > >From what I find on the net, it isn't, but when I try to print something
> > to System.out after the forward call, that works...
> >

As above, control is absolutely returned.  However, there are some
restrictions on what you can do afterwards -- in particular, you can no
longer write to the response (it is assumed that the forwarded-to servlet
took care of that already), so the only prudent thing to do is "return".

> > So did I misread on the www, or is this some bug in my webserver?
> >
> > I'm using JBoss/Tomcat btw...
> >
> > Thanks,
> >
> > Hans
> >

Craig

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org