aspose file tools*
The moose likes Servlets and the fly likes why we need send redirect? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "why we need send redirect?" Watch "why we need send redirect?" New topic
Author

why we need send redirect?

ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
Hi,

I know what send redirect means, it is used to redirect the request to some other resource. One more thing is client can see the different URL on browser.

What I want to know is, why we need this? In which situation we can use send redirect?

Can't we use forward in all situation, I suppose, it is always better to hide such thing from client.

Please comments.
Thanks.
[ November 08, 2005: Message edited by: rathi ji ]
Paul Bourdeaux
Ranch Hand

Joined: May 24, 2004
Posts: 783
Hi rathi ,

sendRedirect must be used when redirecting to a page outside the current context. for instance, I could not forward a request from my domain to a page inside www.javaranch.com.

Also, you should use sendRedirect when you want to ensure that the url is exposed to the user. For instance, if the client needs the ability to bookmark the page, you should use sendRedirect.

Also, when switching protocalls, like from http to https, I believe you need to use a sendRedirect as well.


“Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.” - Rich Cook
subho saha
Ranch Hand

Joined: Jun 15, 2005
Posts: 57
If i want something in my application should be handaled by some other web-application may be built by somebody else, for which i am not responsible in those cases I should use send redirect.
For example say my application wants currency coversion from USD to EURO then calling the yahoo finance with my currency amount may solve my problem
using send redirect.
[ October 21, 2005: Message edited by: subho saha ]
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
Thanks a lot Paul and Subho.

Paul, I think you are prepared to strike SCWCD. All the best.

Paul Bourdeaux
Ranch Hand

Joined: May 24, 2004
Posts: 783
Paul, I think you are prepared to strike SCWCD. All the best.
thanks rathi! I've been "preparing" for a while, but right when I was ready to take it, I change jobs and moved across country... so I've been putting it off. I need to get my butt in gear again though!
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
It's also a way to make the browser to a GET. The POST-redirect-GET pattern has the browser POST an update then GET a fresh view of the changed data. The user can bookmark the view page or refresh it without repeating the POST. I think this is more consistent with the REST view of web architecture; POST should update the resource and GET should show it to you.


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
 
wood burning stoves
 
subject: why we need send redirect?