Welcome Message

Hi, welcome to my website. This is a place where you can get all the questions, puzzles, algorithms asked in interviews and their solutions. Feel free to contact me if you have any queries / suggestions and please leave your valuable comments.. Thanks for visiting -Pragya.

March 9, 2011

forward vs sendRedirect

RequestDispatcher.forward() :

1) Forwards the request to some other servlet/jsp within the same application.
2) The URL in the browser does not change so the client does not get to know that the request is being sent to some other servlet. The process occurs completely within the web container
3) Request attributes are maintained
4) Faster, since everything is at the server side only

Response.sendRedirect()
1) Can forward request to a resource in some other application as well
2) The URL in the browser changes. So the web container returns to the browser indicating that the a new URL should be requested.
3)  Since a new request object is created, any request attributes already stored will be destroyed.
4) Slower, since the round trip to client is involved

No comments: