aspose file tools*
The moose likes JSP and the fly likes forward() VS include() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "forward() VS include()" Watch "forward() VS include()" New topic
Author

forward() VS include()

Yog Ananth
Greenhorn

Joined: Dec 28, 2004
Posts: 27
Please explain what is the difference between forward() and include() in RequestDispatcher.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

They do exactly as their names suggest.

The descriptions in the javadocs are pretty good.
http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/servlet/RequestDispatcher.html


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
James Carman
Ranch Hand

Joined: Feb 20, 2001
Posts: 580
The one key difference between forward() and include() is the fact that forward() clears the output buffer prior to forwarding control to the other servlet (JSPs are servlets ultimately). So, DO NOT forward to another servlet after you've written data to the output stream as the response may already be committed. The include() method merely includes the output of the other servlet inline.


James Carman, President<br />Carman Consulting, Inc.
Nikhil Menon
Ranch Hand

Joined: Nov 22, 2004
Posts: 70
Thank you James.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: forward() VS include()