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

1k views Asked by At

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.

2

There are 2 answers

2
Juned Ahsan On BEST ANSWER

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.

2
JDK On

It works at client side because it uses the url bar of the browser to make another request. So, it can work inside and outside the server.