File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes sendRedirect and forward Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "sendRedirect and forward " Watch "sendRedirect and forward " New topic
Author

sendRedirect and forward

Ghulam Rasool
Greenhorn

Joined: Aug 30, 2003
Posts: 4
We know that incase of forward there is not a full network round trip and same request object is forwarded .. while in sendRedirect there is a full network roundtrip and a new request object is created. there is a temptation to use forward. The Question is that in what cases we should prefer to use the sendRedirect method instead of forward ? which one is better and why ?
Pearlo Muthukumaran
Ranch Hand

Joined: Sep 17, 2002
Posts: 79
Hi,
Your answer is true from the resultant effect point of view. But at the background, redirect results in forwarding the URL to the client and client re-requesting the URL.
Forward
- is a kind of redirect to the resource within the same server
- no client involvement is required
Redirect
- as explained above
therefore, use forward when the redirected resource resides on the same server and use redirect when the resource resides on a different server
Hope this clarifies
Rgds
Muthu
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
You might consider redirect when you want the browser client to know the new URL. That lets the user refresh or bookmark the page. TheServerSide.com proposed a pattern of posting an edit form to the server, then redirecting the browser to an inquiry URL that displays the changed content. The overhead of a second request-response cycle may be acceptable given the improved usability of the site.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: sendRedirect and forward
 
Similar Threads
which one is fast
Work of sendRedirect() method
URGENT!!!!
Forwarding from a servlet to a jsp.
HttpServletResponse Error