File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes RequestDispatcher : content in the forwarding page. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "RequestDispatcher : content in the forwarding page." Watch "RequestDispatcher : content in the forwarding page." New topic
Author

RequestDispatcher : content in the forwarding page.

Celinio Fernandes
Ranch Hand

Joined: Jun 28, 2003
Posts: 547

Hi,
I am having some serious doubts regarding the behaviour of the RequestDispatcher method.


displays



Why does it display "Back in ServletA".

I thought that after any Requestdispatch all the contents of the forwarding page were lost ?!?!

Please give me some explanations.
Thanks
[ October 24, 2006: Message edited by: Max Fernandes ]

SCJP 1.4, SCWCD 1.4, SCBCD 1.3, SCBCD 5
Visit my blog
wise owen
Ranch Hand

Joined: Feb 02, 2006
Posts: 2023
Actually the RequestDispatcher.forward and RequestDispatcher.include are just method calls to the other servlet.

Control is indeed returned to the line after this line once it completes. The body of the code after the forward will still be processed and any unhandled exceptions will be thrown to requesting servlet.

The 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".
[ October 24, 2006: Message edited by: wise owen ]
Niranjan Deshpande
Ranch Hand

Joined: Oct 16, 2005
Posts: 1277


i wonder how the above code worked for you, because as far as i know,
to forwad to a servlet one needs to use the getNamedDispatcher( ) method.
So ???


SCJP 1.4 - 95% [ My Story ] - SCWCD 1.4 - 91% [ My Story ]
Performance is a compulsion, not a option, if my existence is to be justified.
Celinio Fernandes
Ranch Hand

Joined: Jun 28, 2003
Posts: 547

No,
String fwdPath = "/ServletB";
RequestDispatcher rd = request.getRequestDispatcher(fwdPath);
works.
There are 3 ways to get a RequestDispatcher.
And by the way, i am not sure, but I think getNamedDispatcher is not at the exam.
You should focus on the other 2 ways instead.
Can someone confirm this ?
[ October 24, 2006: Message edited by: Max Fernandes ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: RequestDispatcher : content in the forwarding page.