Forward & include methods

What are forward & include methods? Why these are used?

Questions by RajeshKumar.Guru

Showing Answers 1 - 3 of 3 Answers

Both forward() and include() are concrete methods of the RequestDispatcher class in the Servlet context.

forward() - this method is used to show a different resource in place of the servlet originally requested. This resource may be a jsp, a servlet etc. When a request is sent from the client to the web server through an url , the web container intercepts the request and sends it to another resource without the knowledge of the client browser. And a response is received from that resource after processing of the request is done.

include() - this method is used to tag in the contents of a  resource as a part of the response flow as if it were part of the calling servlet. If you include a jsp or a servlet, it must not attempt to change the response status code or the http headers, as any such request will be ignored.

delindia fathima

  • Dec 20th, 2011
 

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.

  Was this answer useful?  Yes

SUJATA WAGHMARE

  • Jan 10th, 2014
 

1 ]forward method :client send request first servlet and first servlet forward the request second servlet most important things is second servlet give a response to clinet....
2]include method:clinet send request first servlet and first servlet forward the request second servlet but second servlet generate the response then second servlet return the response to frist servlet then frist servlet given a response to clinet....

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions