Please send your Questions & Answers or Feedback to "mohan@javabook.org"

What is the difference between the include() and forward() methods?


The RequestDispatcher include() method inserts the the contents of the specified resource directly in the flow of the servlet response, as if it were part of the calling servlet.

The RequestDispatcher forward() method is used to show a different resource in place of the servlet that was originally called.

If you include a servlet or JSP document, the included resource must not attempt to change the response status code or HTTP headers, any such request will be ignored.
The forwarded resource may be another servlet, JSP or static HTML document, but the response is issued under the same URL that was originally requested. In other words, it is not the same as a redirection.

The include() method is often used to include common "boilerplate" text or template markup that may be included by many servlets.

The forward() method is often used where a servlet is taking a controller role; processing some input and deciding the outcome by returning a particular response page.

Related Posts Plugin for WordPress, Blogger...
Flag Counter