Servlet Forward vs Redirect

To do redirect, server sends back a HTTP response status 302. Upon receiving such response, browser is obligated to request page from the new location, hence redirect happens.

HTTP/1.1 302 Object moved
Location: somewhere/newlocation.jsp

Forward, on the other hand, happens internally on the server, and browser is not aware of it at all.

That explains why we need to encodeURL before redirect but not before forward; why states are kept when forward but not when redirect; why redirect method is on Response object but forward is on RequestDispatcher object.

Technorati Tags:

Comments

Anonymous said…
But i can't understand when we will go for a forward & when for a Re-direct :(

Popular Posts