Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

forward() VS include()  RSS feed

 
Yog Ananth
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please explain what is the difference between forward() and include() in RequestDispatcher.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
James Carman
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Nikhil Menon
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you James.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!