AF
HomeTagSubmit NotesAsk AnythingLoginSubscribe Us
AF
1. Feel Free to ask and submit anything on Anyforum.in and get satisfactory answer
2. Registration is not compulsory, you can directly login via google or facebook
3. Our Experts are looking for yours ?.



java-servlet: What is the difference between forward() method of RequestDispatcher and sendRedirect() method ?

forward() and sendRedirect() both methods are used to move from one page to another page, so where should we use forward() and sendRedirect()?

java x 211
servlet x 20
Posted On : 2013-12-01 18:27:13.0
profile Garima Gupta - anyforum.in Garima Gupta
596129554554
up-rate
5
down-rate

Answers


Following is the key difference between forward() and sendRedirect() :
  • forward() sends the same request to another resource while sendRedirect() method sends new request always because it uses the URL bar of the browser.
  • forward() method works at server side and sendRedirect() method works at client side.
  • forward() method works within the server only and sendRedirect() method works within and outside the server.

sendRedirect() is used when we don´t want to send the same request on another page we received. Consider the example of login form : after successful login we should always use sendRedirect() to move to the welcome page. and similarly whenever we perform any successful database operation we always use sendRedirect(). On getting any error and exception we should use forward().

Posted On : 2013-12-01 18:44:11
Satisfied : 1 Yes  0 No
profile Rishi Kumar - anyforum.in Rishi Kumar
523188245674
Reply This Thread
up-rate
4
down-rate



Post Answer
Please Login First to Post Answer: Login login with facebook - anyforum.in