What is differents between forword(),include() and sendRedirect()? In which circumtances all are used? Give Proper Examles.

Questions by shivam_it3

Showing Answers 1 - 4 of 4 Answers

murugan

  • Feb 26th, 2006
 

Using forward(request,response) u are forwarding the current to page to another page so that the response will results in forwarded page

Using include(request,response) u are including one page result to the current page so that the response will not generate in another page it will generate in the current page i.e where the page is included

Using sendRedirect() method it is done by client side the url will be changed whatever the page u are calling

ex:if u call hello.jsp from http://localhost:8080/d1/d2  if we redirect to hello.jsp in client side the url will change i.e visible to the user which page u are calling http://localhost:8080/d1/hello.jsp

and another use of sendRedirect is it send information to another JVM also

santh kumar

  • Mar 16th, 2006
 

Hi Buddies,

<jsp:forward> element allows us to forward the request object which contains the client request to other jsp file,servlet file or even static HTML file.the code(statements) after the <jsp:forward> will not get executed by the JSP container.the forwarded file should be within the web application.

<jsp:include> element allows us to include a jsp file or a HTML file in the current jsp file.the code(statements) after the <jsp:include> will be get executed by the JSP container.the included file should be within the web application.

the abv 2 r methods of RequestDispatcher interface.

sendRedirect()  is a method of ServletResponse interface.it takes a URL as argument,the response is transfered(forwarded) to that file even it is in another web application.here the response comes the client,by using that(URL or where the source is available)client needs 2 send another request.

To simply say,assume a scenario-

 a client sends a request to a servlet,the server responds with a response which says where the requested resource  is available.it may be means that temporarily the requested resource is not available or available somewhere.

  Was this answer useful?  Yes

Anil kumar

  • Sep 16th, 2006
 

include() : This method is used to include another page into the current page, so the response is generated at the current page.forward() : This method is used to forward the response ot the current page to another page, so the response is generated at another page... Thank you....

  Was this answer useful?  Yes

deepak2145

  • Nov 15th, 2007
 

akshay

jsp include directive is used to take the response from the called html/jsp page whereas the jsp inlude action includes the contents of the called servlet/jsp .

  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