aspose file tools*
The moose likes Servlets and the fly likes RequestDispatcher Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "RequestDispatcher" Watch "RequestDispatcher" New topic
Author

RequestDispatcher

Cameron Park
Ranch Hand

Joined: Apr 06, 2001
Posts: 371
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

Joined: Jan 07, 1999
Posts: 6920
'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.


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Poornima Shetty
Greenhorn

Joined: Dec 12, 2000
Posts: 26
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.
 
jQuery in Action, 2nd edition
 
subject: RequestDispatcher
 
Similar Threads
Compilation Error
Proper technique for forwarding servlets
RequestDispatcher
More simple doubts....errr
RequestDispatcher not throwing IllegalStateException