This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
forward() method is faster than sendRedirect But the main thing is forward() works only within the webapplication. But whereas with the sendRedirect() method we can redirect to any webapplication.(which cant be done using forward() method.)
But if u want to redirect a servlet using forward() method only which is in other webapplication u can also do that. For this you need to get an object of ServletContext and then use forward() method.
see the code below:- ServletContext servletcontex=ServletContext.getContext(); RequestDispatcher requestDispatcher=ServletContext.getRequestDispatcher("/contextname"); requestDispatcher.forward(request,response); Note:- Before doing this u change your CrossContext attribute to true in your context in server.xml file since it is false by default
Originally posted by Shrawan Bhageria: hi all what does it mean The sendRedirect() involves a round trip. thanks regards shrawan
By "round trip" he means it goes from the server to the client (browser) and then another request is originated from the browser. When you use sendRedirect it sends a HTTP code 302 to the browser with the new URL. The browser will then initiate a HTTP GET on the new URL.