• Post Reply Bookmark Topic Watch Topic
  • New Topic

url redirecting  RSS feed

 
Suresh Appagundi
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

i type the following url in the browser

"http://dreamadream.org/"

and got redirected to below

http://dreamadream.org/dreams/avs/home/

In the browser its been taken care

but same action i need it using java net package.

I am using URL and HttpURLConnection to connect to "http://dreamadream.org/"

but i should get redirect to "http://dreamadream.org/dreams/avs/home/
".

HOW TO DO THAT IN JAVA PROGRAM USING NET PACKAGE OR ANY OPENSOURCE LIKE

HTTPCLIENT FORM COMMONS.

VERY URGENTLY REQUIRED.

THANKS IN ADVANCE
 
Scott Selikoff
author
Bartender
Posts: 4081
21
Eclipse IDE Flex Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Short answer is have your java output an HTML META-tag that performs an immediate redirect. The better way though, if this is a permenant redirect, is to set the redirect up on your server so that your server handles the redirect.

Third, if this is a servlet, you can also perform a servlet forward which the java application moves the user to a different page. Although I find this to be the most costly solution for simple redirects.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Scott imagines you're writing the server end and want to do a redirection, but I'm pretty sure you're working on the client end. The answer is that to do this with HttpURLConnection, you'd have to look for the "redirect" HTTP response code, parse the response, and open the new URL yourself. I'm going to move this to our "Sockets and Internet Protocols" forum where someone can answer your follow-on questions.
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That server doesn't send an HTTP redirect code. It does exactly what Scott suggested and sends a META tag for an immediate refresh, like this:

<META HTTP-EQUIV='REFRESH' CONTENT='0; URL=/dreams/avs/home/'>

So the HttpURLConnection's ability to automatically follow redirects doesn't apply because this isn't a redirect. Whatever program is reading this data would have to be able to interpret that META tag and act accordingly. I have no idea whether Jakarta Commons Net or any other open-source code does that automatically.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Interpreting META tags would suppose a knowledge of HTML, which is beyond what Commons Net or HttpClient does.

HttpUnit can do this through the use of an HTML parser.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!