Jump to content


Photo

Difference between forward(request,response) and SendRedirect(url) in Servlet ?







  • Please log in to reply
1 reply to this topic

#1 ChetanaS






Posted 20 March 2006 - 06:48 PM

- PLEASE SHARE

Question of the Day :- 20 March 2006
----------------------------------------------------------------
Explain the differences between forward(request,response) and SendRedirect(url) in Servlet ?
----------------------------------------------------------------


#2 kavin

kavin

    Newbie

  • Members
  • Pip
  • 4 posts

Posted 17 April 2006 - 11:38 AM

Hi,Difference between forward(request,response) and SendRedirect(url) in Servlet ? RequestDispatcher r=request.getRequestdispatcher("good.jsp"); r.forward(request,response); response.sendRedirect("/jj.html");Forward :its a server side request...see its request.getRequestdistatcher()SendRedirect:its a client side request...see its response.sendRedirect()forward:Its url doesnt change on the browserSendRedirect:The user sees the new URLIn real time people doesnt use sendRedirect mostly due to performance Hit.Now a days nobody is using sendRedirect often.i think so..HOW THE PROCESS WILL HAPPEN IS:1.forward: 1 first the url is typed in the browser. 2 request then goes to server and then container and checks with DD for the url matching 3 the servlet then tells that it should go to another web appln. 4 Now in this moment it will call RequestDispatcher and dispatch the request to other page ..here good.jsp 5 Now the browser as usual get the responsse from server thro container and displays the page.The browser doesnot know the resultant page i mean good.jsp only created the result in the current page2.sendRedirect: 1 first the url is typed in the browser. 2 request then goes to server and then container and checks with DD for the url matching 3 the servlet then tells that it should go to complete different URL 4 Now Servlet calls sendRedirest on response and then it goes to browser thro server including the status code 301 and location Header as the value 5 Now thw browser gets the status code and location header.so that it makes a new request using the URL i mean the Location header value(Location header value=URL) in the prevoious response. 6 THE USER DOES NOTICE THE URL CHANGE IN BROWSER BAR 7 then as usual the request go and hit the container thro server and looks for DD the matching servlet and then return the response and the o/p will get displayed...regards,kavitha[/font]Hi,Difference between forward(request,response) and SendRedirect(url) in Servlet ? RequestDispatcher r=request.getRequestdispatcher("good.jsp"); r.forward(request,response); response.sendRedirect("/jj.html");Forward :its a server side request...see its request.getRequestdistatcher()SendRedirect:its a client side request...see its response.sendRedirect()forward:Its url doesnt change on the browserSendRedirect:The user sees the new URLIn real time people doesnt use sendRedirect mostly due to performance Hit.Now a days nobody is using sendRedirect often.i think so..HOW THE PROCESS WILL HAPPEN IS:1.forward: 1 first the url is typed in the browser. 2 request then goes to server and then container and checks with DD for the url matching 3 the servlet then tells that it should go to another web appln. 4 Now in this moment it will call RequestDispatcher and dispatch the request to other page ..here good.jsp 5 Now the browser as usual get the responsse from server thro container and displays the page.The browser doesnot know the resultant page i mean good.jsp only created the result in the current page2.sendRedirect: 1 first the url is typed in the browser. 2 request then goes to server and then container and checks with DD for the url matching 3 the servlet then tells that it should go to complete different URL 4 Now Servlet calls sendRedirest on response and then it goes to browser thro server including the status code 301 and location Header as the value 5 Now thw browser gets the status code and location header.so that it makes a new request using the URL i mean the Location header value(Location header value=URL) in the prevoious response. 6 THE USER DOES NOTICE THE URL CHANGE IN BROWSER BAR 7 then as usual the request go and hit the container thro server and looks for DD the matching servlet and then return the response and the o/p will get displayed...regards,kavitha[/font]




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users