aspose file tools*
The moose likes Servlets and the fly likes RequestDispatcher include and forward Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "RequestDispatcher include and forward" Watch "RequestDispatcher include and forward" New topic
Author

RequestDispatcher include and forward

pankaj kapoor
Greenhorn

Joined: Sep 22, 2005
Posts: 17
could anyone tell me the difference between
req.getRequestDispatcher("try.jsp" ).forward(req ,resp)
and
req.getRequestDispatcher("try.jsp" ).include(req ,resp);

Thanks in advance
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61762
    
  67

What did you not understand after reading the JavaDoc for these methods?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
pankaj kapoor
Greenhorn

Joined: Sep 22, 2005
Posts: 17
what I have understood is that both of the methods direct to the JSP file mentioned in the method argument. ie include or forward.
dema rogatkin
Ranch Hand

Joined: Oct 09, 2002
Posts: 294
I think after forward you are pretty much done with request/response and can't use it anymore to change content received by a browser. In case of include you can.


Tough in space?, <a href="http://tjws.sf.net" target="_blank" rel="nofollow">Get J2EE servlet container under 150Kbytes here</a><br />Love your iPod and want it anywhere?<a href="http://mediachest.sf.net" target="_blank" rel="nofollow">Check it here.</a><br /><a href="http://7bee.j2ee.us/book/Generics%20in%20JDK%201.5.html" target="_blank" rel="nofollow">Curious about generic in Java?</a><br /><a href="http://7bee.j2ee.us/bee/index-bee.html" target="_blank" rel="nofollow">Hate ant? Use bee.</a><br /><a href="http://7bee.j2ee.us/addressbook/" target="_blank" rel="nofollow">Need contacts anywhere?</a><br /><a href="http://searchdir.sourceforge.net/" target="_blank" rel="nofollow">How to promote your business with a search engine</a>
pankaj kapoor
Greenhorn

Joined: Sep 22, 2005
Posts: 17
I am still not clear with your comment

'I think after forward you are pretty much done with request/response and can't use it anymore to change content received by a browser. In case of include you can.
'
could you elaborate on it.
Shrinivas Mujumdar
Ranch Hand

Joined: Aug 27, 2004
Posts: 328
Hello PAnkak,
forward
Once you forward the request from say Servlet A to any other Servlet/JSP control gets transferred from Servlet A to forwarded patrty & it never returns back to A for that request.
Include
In include what you are doing is if Servlet A(Above example) is including the response of other Servlet/JSP(say B or B.jsp) so momentarily Control goes to B or B.jsp (they will genrate the response) control comes back to A & generated response is added in A's Response.


I hope this helps....feel free if you need more explanation.
Shinivas
Vishnu Prakash
Ranch Hand

Joined: Nov 15, 2004
Posts: 1026
Just updated the servlet FAQ. You can find it here


Servlet Spec 2.4/ Jsp Spec 2.0/ JSTL Spec 1.1 - JSTL Tag Documentation
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: RequestDispatcher include and forward