Re: RequestDispatcher forward and include methods
"Karr, David" <[email protected]>
| Newsgroups | gmane.comp.java.sun.servlet |
|---|---|
| Message-ID | <[email protected]> |
This always causes confusion. Here's one way to illustrate this: except for schemes involving exceptions, there is no way for a "called" method to cause the code in the "calling" method to skip the rest of the method. In short, calling the "forward()" method may transfer "control", but it's only logical control over what servlet is supposed to be generating output to the client. It has nothing to do with controlling execution of code in methods. So, even though the call to "forward()" will have generated output from the "called" servlet, as soon as it returns from the "forward()" call, if there's further code in the calling method, it will be executed. > -----Original Message----- > From: Hiren Dossani [mailto:[email protected]] > > afaik, forward method of RequestDispatcher transfers control to the > forwarded servlet. means one can never come back to the fowarding servlet. > however, i don't get why the last statement in the following forwarding > servlet was executed after using RequestDispatcher's forward method. > > forwarding servlet code: > ------------------------- > > out.println("<font color=\"ff0000\"><h2>This text is from > TallyPage1</font>\n<br><p>"); > RequestDispatcher r = > getServletContext().getNamedDispatcher("Tally"); > r.forward(req, resp); > out.println("<font color=\"ff0000\"><h4>This line is after forward > method</font>\n<br><p>"); > > > forwarded servlet code: > ---------------------- > out.println("in forwarded servlet"); > > i shouln't see the last line in forwarding serlvet being displayed on the > browser. ___________________________________________________________________________ To unsubscribe, send email to [email protected] and include in the body of the message "signoff SERVLET-INTEREST". Archives: http://archives.java.sun.com/archives/servlet-interest.html Resources: http://java.sun.com/products/servlet/external-resources.html LISTSERV Help: http://www.lsoft.com/manuals/user/user.html