This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "forward() VS include()" Watch "forward() VS include()" New topic

forward() VS include()

Yog Ananth

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

Joined: Dec 11, 2004
Posts: 13410

They do exactly as their names suggest.

The descriptions in the javadocs are pretty good.

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:
subject: forward() VS include()
Similar Threads
forward and include attributes??
Regarding call of two servlets on single action?
Request Dispatcher.
forwarded to jsp displays content in previous jsp