Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Difference between requestDispatcher.forward() and RequestDispatcher.include()?

 
rk
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pls Give me a brief explain with examplle of this qusetion..
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65111
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"rk",

There aren't many rules that you need to worry about here on the Ranch, but one that we take very seriously regards the use of proper names. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks!
bear
Forum Bartender
[ October 13, 2005: Message edited by: Bear Bibeault ]
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by rr rk:
Pls Give me a brief explain with examplle of this qusetion..


Please read the docs. There is no other better substitute.

RequestDispatcher API Docs
[ October 14, 2005: Message edited by: Adeel Ansari ]
 
Ishan Bhatt
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The difference is in their name itself.

forward will forward the request to the new servlet/jsp.
Any out.println() statements in the servlet from where you call the forward method would not be of any use. You can't even call response.getWriter() method in this case. You can only do that in the servlet to which the control has been forwaded.

include will process the included servlet/jsp and any out.println()/html stuff will be included, and then control will come back to the servlet/jsp that called include method.
 
Vishnu Prakash
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out the servlet collections link
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic