sendRedirect() is a such type of method which redirects the response to another resource. This method makes the client(browser) to create a new request to get to the resource. The client can see the new url in the browser. sendRedirect() accepts relative URL, so it can go for resources inside or outside the server.
The main difference between a redirect and a request dispatching is that, redirect method makes the client(browser) create a new request to get to the resource, the user can see the new URL while request dispatching get the resource in same request and URL does not changes. Also, another very important difference is that, sendRedirect() works on response object while request dispatch work on request object.
Let's see a demo program:When to use sendRedirect() method?