This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Servlets and the fly likes How to recognize redirects? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to recognize redirects?" Watch "How to recognize redirects?" New topic
Author

How to recognize redirects?

Marwan Oweis
Greenhorn

Joined: Apr 21, 2008
Posts: 2
All,

I have a servlet (call it Servlet A) that once called opens an Http Connection on another server with another servlet (call it Servlet B). This is done using java.net.HttpURLConnection.

The URL for Servlet B actually points to a load balancer, so my request gets redirected to the appropriate host.

My question is as follows: is there a way for Servlet A to get the host or ip to which it gets redirected?

Let me give an example:
1) Servlet A opens a connection to http://www.example.com/checkExample
2) www.example.com is the host name of load balancer. It redirects the request to http://www.redirectexample.com/checkExample

Is there a way for Servlet A to recognize/figure out the redirect URL: www.redirectexample.com?



Thanks,
Marwan
SCJP5, SCWCD5
[ June 09, 2008: Message edited by: Marwan Oweis ]
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Not that I can see.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
Looking at the JavaDocs it appears that setFollowRedirects is true by default. Perhaps you could set that to false and handle the new address in your code.

Bill
Marwan Oweis
Greenhorn

Joined: Apr 21, 2008
Posts: 2
Originally posted by William Brogden:
Looking at the JavaDocs it appears that setFollowRedirects is true by default. Perhaps you could set that to false and handle the new address in your code.

Bill


Thanks! I saw that but it never registered.

I found a code sample in the apache commons project:


[ June 10, 2008: Message edited by: Marwan Oweis ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to recognize redirects?
 
Similar Threads
Apache HttpClient posing trouble
Request server port methods
lost session attributes
Mock Questions
Difference between forward() and sendRedirect()