Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

RequestDispatcher

 
Cameron Park
Ranch Hand
Posts: 371
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not clear about the two methods from RequestDispatcher. Does forward() ever return from within the servlet's service mthod that called it? If so, then
protected void doGet(HttpServletRequest req, HttpServletREsponse res) throws IOException, ServletException{
RequestDispatcher rd = getServletContext().getRequestDispatcher("response");
rd.forward(req, res);
getPrintWriter("Do you see me??");
}
and
protected void doGet(HttpServletRequest req, HttpServletREsponse res) throws IOException, ServletException{
RequestDispatcher rd = getServletContext().getRequestDispatcher("response");
rd.include(req, res);
getPrintWriter("Do you see me??");
}
How do they differ functionally?
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
'forward' and 'include' primarily vary in what they do with the context, headers and so on. You will see more of an effect in the code you are calling than in the code which calls it.
 
Poornima Shetty
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
basically forward just takes the pain of forwarding the request and response objects to the required jsp,but in include the servlet invokes the objects and substitites their corresponding values and then sends the result to the jsp ,in addition to which it also does some cleaning up of any resources thats no more required.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic