Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

forward() VS include()

 
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic