• 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

About Forward and Include method in Servlet

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi to all my JavaRanch Friends this is Anurag ...

I want to know how Forward and Include method in RequestDispatcher work??
and please send me the code also if it is possible for you.

Thanks in advance.!!!
[ September 11, 2007: Message edited by: Bear Bibeault ]
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by sharma anurag:
and please send me the code also if it is possible for you.



That's not quite how things work here on the Ranch. You'll get all the help you need to write your own code. What specific questions do you have about dispatching? Are you having problems with some existing code?
 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi sharma, its very simple...

see forward -- request goes to another resource from current position ,you cant print anything after this statement.if you do so it throws an exception

where as include : you are processing another resource with in your page .. you can print anything after this statement.no problems

i think you understand clearly...
 
Ranch Hand
Posts: 464
Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1) forward: When you use a forward, you can forward your request to any other resource that is managed by your web container. This means that you can forward your request to any other servlet or a JSP and continue to process the request. All the attributes present in that request is available for you for you to continue processing. And once the request is dispatched, it is committed. You cannot continue processing further.

....
RequestDispatcher view = request.getRequestDispatcher("\Servlet1");
view.forward(request,response);
// Don't do anything here. Its committed as you have forwarded to another resource.


2) include: Its like taking the help of another container managed resource to do some processing. You send your request to the other resource, perform the requested operation in another resource and get back to the same resource and continue processing further.

....
RequestDispatcher view = request.getRequestDispatcher("\Servlet1");
view.include(request,response);
// you can continue processing the request from here
.....
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic