Please send your Questions & Answers or Feedback to ""

What's the difference between forward() and sendRedirect() methods?

A forward is performed internally by the servlet.

A redirect is a two step process, where the web application instructs the browser to fetch a second URL, which differs from the original.

The  browser is completely unaware that it has taken place, so its original URL remains intact.

The browser, in this case, is doing the work and knows that it's making a new request.

Any browser reload of the resulting page will simple repeat the original request, with the original URL

A browser reloads of the second URL ,will not repeat the original request, but will rather fetch the second URL.

Both resources must be part of the same context (Some containers make provisions for cross-context communication but this tends not to be very portable)

This method can be used to redirect users to resources that are not part of the current context, or even in the same domain.

Since both resources are part of same context, the original request context is retained Because this involves a new request, the previous request scope objects, with all of its parameters and attributes are no longer available after a redirect.
(Variables will need to be passed by via the session object).

Forward is marginally faster than redirect.

redirect is marginally slower than a forward, since it requires two browser requests, not one.

Related Posts Plugin for WordPress, Blogger...
Flag Counter