aspose file tools*
The moose likes Servlets and the fly likes How does a servlet know when it is being redirected to the right page 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 "How does a servlet know when it is being redirected to the right page" Watch "How does a servlet know when it is being redirected to the right page" New topic
Author

How does a servlet know when it is being redirected to the right page

Vivian Ryder
Greenhorn

Joined: Nov 12, 2004
Posts: 20
I am writing a servlet that will send certain parameters to a foreign servlet which will decide on which web page to display basing on the parameters sent. And my web application will process accordingly depending on which web page is sent. My problem is that how will my servlet know which web page it is being redirected. Is there any way I can know the URL of the web page that I am being redirected to?

Thank you

Vivian
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

Why not ask in our Servlets forum? Here, I'll move this there for you.


[Jess in Action][AskingGoodQuestions]
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
How is your servlet communicating with the foreign one ... URL or HttpURLConnection or something like that? Look in the doc or on Google for a "follow forward" option that makes one of those (forget which) automatically follow any forward headers sent back by the foreign servlet. I've set this to true before (maybe the default) but never really tested how well it works.


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
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
redirect is a clientside action therefore the HTTP response will contain the redirect URL as well as a return code in the 300 range indicating you're being redirected.

If the request is forwarded otoh you will notice nothing and you shouldn't bother as forward is purely serverside and completely transparent to the client (all the client notices is that the actual data in the response are different for different requests).


42
Vivian Ryder
Greenhorn

Joined: Nov 12, 2004
Posts: 20
Thanks for the reply, but how do I retrieve the URL contained in the HTTPResponse? Is the method losted in javadoc?

Thank you
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How does a servlet know when it is being redirected to the right page