- RequestDispatcher forward() is used to forward the same request to another resource whereas ServletResponse sendRedirect() is a two step process. In sendRedirect(), web application returns the response to client with status code 302 (redirect) with URL to send the request. The request sent is a completely new request.
- forward() is handled internally by the container whereas sednRedirect() is handled by browser.
- We should use forward() when accessing resources in the same application because it’s faster than sendRedirect() method that required an extra network call.
- In forward() browser is unaware of the actual processing resource and the URL in address bar remains same whereas in sendRedirect() URL in address bar change to the forwarded resource.
- forward() can’t be used to invoke a servlet in another context, we can only use sendRedirect() in this case.
JSP / Servlet - Interview
Saturday, 5 September 2015
What is difference between ServletResponse sendRedirect() and RequestDispatcher forward() method?
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment