• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

RequestDispatcher : content in the forwarding page.

 
Ranch Hand
Posts: 563
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 2023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 1277
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 563
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic