1

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.

CoderNeji
  • 2,056
  • 3
  • 20
  • 31
Dil.
  • 1,996
  • 7
  • 41
  • 68

2 Answers2

1

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.

Juned Ahsan
  • 67,789
  • 12
  • 98
  • 136
0

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.

JDK
  • 83
  • 1
  • 12
  • Thank u. thats simple. & can you explain me why requestDispatcher is being server side. – Dil. Jun 26 '15 at 05:16
  • A RequestDispatcher object can forward a client's request to a resource or include the resource itself in the response back to the client. A resource can be another servlet, or an HTML file, or a JSP file, etc. You can also think of a RequestDispatcher object as a wrapper for the resource located at a given path that is supplied as an argument to the getRequestDispatcher method. – JDK Jun 26 '15 at 05:40