my dog learned polymorphism*
The moose likes Servlets and the fly likes About Forward and Include method in Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "About Forward and Include method in Servlet" Watch "About Forward and Include method in Servlet" New topic
Author

About Forward and Include method in Servlet

sharma anurag
Greenhorn

Joined: Aug 29, 2007
Posts: 16
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 ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60059
    
  65

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?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
srinivas.b
Ranch Hand

Joined: Oct 26, 2006
Posts: 58
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...
S Venkatesh
Ranch Hand

Joined: Jun 27, 2005
Posts: 464

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
.....
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: About Forward and Include method in Servlet
 
Similar Threads
SCWCD exam: which methods should be known?
http method
RequestDispatcher include and forward
Request Dispatcher.
Servlet Communication