• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

RequestDispatcher include and forward

 
pankaj kapoor
Greenhorn
Posts: 17
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
could anyone tell me the difference between
req.getRequestDispatcher("try.jsp" ).forward(req ,resp)
and
req.getRequestDispatcher("try.jsp" ).include(req ,resp);

Thanks in advance
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64204
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What did you not understand after reading the JavaDoc for these methods?
 
pankaj kapoor
Greenhorn
Posts: 17
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what I have understood is that both of the methods direct to the JSP file mentioned in the method argument. ie include or forward.
 
dema rogatkin
Ranch Hand
Posts: 294
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think after forward you are pretty much done with request/response and can't use it anymore to change content received by a browser. In case of include you can.
 
pankaj kapoor
Greenhorn
Posts: 17
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am still not clear with your comment

'I think after forward you are pretty much done with request/response and can't use it anymore to change content received by a browser. In case of include you can.
'
could you elaborate on it.
 
Shrinivas Mujumdar
Ranch Hand
Posts: 328
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello PAnkak,
forward
Once you forward the request from say Servlet A to any other Servlet/JSP control gets transferred from Servlet A to forwarded patrty & it never returns back to A for that request.
Include
In include what you are doing is if Servlet A(Above example) is including the response of other Servlet/JSP(say B or B.jsp) so momentarily Control goes to B or B.jsp (they will genrate the response) control comes back to A & generated response is added in A's Response.


I hope this helps....feel free if you need more explanation.
Shinivas
 
Vishnu Prakash
Ranch Hand
Posts: 1026
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just updated the servlet FAQ. You can find it here
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic