Hello,
What is the basic difference between RequestDispatcher and sendRedirect method ?
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Satyapriya NayakRank #47 · 31.5K reputationPosted Oct 13, 2011, 10:46 AM EDT
response.sendRedirect():
This is complete new request to browser.
Request is not maintained so data stored in request object not available to redirect page.
You have to store data in session to get in the redirect jsp.
You can pass data like response.sendRedirect("/abc.jsp?name=satya). Then in the abc.jsp you have to get name using request.getParameter("name");
This is fresh call to server.
For example .. you forwarded from /login to login.jsp
in the browser you can see /login.jsp....
requestDispatcher.forward() : This not new request. Just transfer the content to forwarded jsp.
You can store data in request and able to get in redirect jsp.
For example .. you forwarded from /login to login.jsp
in the browser you can see /login ....
Disadvantage - browser refresh call to /loginj again. may be duplicate data submit.
Also refer the below link
http://www.roseindia.net/help/java/s/forward-vs-redirect.shtml
Prabhu RajaRank #861 · 2.6K reputationPosted Oct 13, 2011, 10:09 PM EDT
For more reference : Click Here
Vikas MishraRank #559 · 4.3K reputationPosted Nov 21, 2011, 12:48 PM EST