Search code examples
jakarta-eeservletsclient-sideserver-siderequestdispatcher

Does sendRedirect() happens at client side or at the server side?


The theory says that A request dispatch happens on the server, while a redirect happens on the client.

Aren't that the both methods used in the servlet? Then both should happen at server side. Right?
Or did i misunderstood what is client/server side?
Please give me clear explanation with some examples if you can.
Thank you.


Solution

  • redirect is a signal that server sends to the client with the means of HTTP response header.

    HTTP 302 code is used along with a location header in the response from server. When client receives 302, it then uses URI specified by the Location header to fire a new request.

    A request dispatch happens on the server, while a redirect happens on the client.

    So redirection is initiated by the server but actual redirection happens on the client side, because client is responsible to send the new request.