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 How do I find URL after redirection? 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 do I find URL after redirection?" Watch "How do I find URL after redirection?" New topic
Author

How do I find URL after redirection?

the shiroi
Greenhorn

Joined: Mar 30, 2001
Posts: 4
Hi,
Is there anyway to find the URL of a webpage if you were
redirected?
For example, a valid URL would be http://www.vvvvvvv.com. When
I do a url.openConnection(), I am able to get the inputstream to
a web page. However, this is really a page located at http://www.vvvvvvvv.com/xxxx_home/index.jsp Is there a way of
finding out this URL from my initial URL connection?
shiroi


Good if got as wished.<BR>Better if not.
maha anna
Ranch Hand

Joined: Jan 31, 2000
Posts: 1467
From Java Doc of Servlet 2.2 API, got this inforamtion. Please check if this is useful to you. THis mehtod "getRequestURI" is from HTTPServletRequest object.
Also please re-register with your first and last names.
regds
maha anna

the shiroi
Greenhorn

Joined: Mar 30, 2001
Posts: 4
Thanks maha. But it dose not help me, as the redirection would be done by webservers (any webserver), I am just trying to make a urlconnection to a webserver and if at all I am redirected, how can I get the redirected url?
Thanks once again.
shiroi.
maha anna
Ranch Hand

Joined: Jan 31, 2000
Posts: 1467
How did you test? Is it like following code?. I couldn't succeed getting the redirected url with just con object. All we get is whatever we first asked for , which is www.vvvvv.com url!
Others can add to this!
regds
maha anna
the shiroi
Greenhorn

Joined: Mar 30, 2001
Posts: 4
Hai, Back again. Yes, you are rigt Maha, in all cases we get the same url that we use while creating the con obj. I tried with all the keys in the getHeaderField() but in some cases (for ex. try connecting to http://www.contakt.net or http://www.icope.com) you get the redirected url with key int = 2 i.e, under the sub heading Content-Location. But then this is not the same in all cases, there has to be a way!
Shiroi.
the shiroi
Greenhorn

Joined: Mar 30, 2001
Posts: 4
Hi,
Also i observed that the response code(HttpURLConnectionObject.getResponseCode()) returned is not 3xx when there exists a redirection (as stated in the J2SE docs.). For example www.viviance.com (redirected to http://www.viviance.com/viviance_home/index.jsp) or www.icope.com (redirected to www.icope.com/icope/) or www.dw.org (redirected to www.dwelle.de/), strange that rCode returned is 200 and not 3xx. Any idea over this would be of great help!
shiroi.

[This message has been edited by the shiroi (edited April 04, 2001).]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How do I find URL after redirection?