Pages

Monday 2 December 2013

Difference between include and forward of RequestDispatcher in Servlet




include()  

forward()

1. It is used to include the response to the source servlet.

1. It is used to forward the request to the other servlet or JSP page.  
2. Response get committed after including all other resources(servlet/JSP) responses.  
2. Response get committed by the RequestDispatcher object and also close the response stream. 
3. A servlet class can have multiple include statement to execute. 
3. A servlet class can have multiple forward statement conditionally but will execute only one.  
4. After executing include() control will back to the source servlet and will add information to response object. 
4. After executing forward() control will
back to the source servlet but other informations cannot be added to that response object.

No comments:

Post a Comment