Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

RequestDispatcher : content in the forwarding page.

 
Celinio Fernandes
Ranch Hand
Posts: 549
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
wise owen
Ranch Hand
Posts: 2023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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 ???
 
Celinio Fernandes
Ranch Hand
Posts: 549
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic