HomeTagSubmit NotesAsk AnythingLoginSubscribe Us
1. Feel Free to ask and submit anything on 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 - Garima Gupta


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 - Rishi Kumar
Reply This Thread

Post Answer
Please Login First to Post Answer: Login login with facebook -