Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / January 2006

Tip: Looking for answers? Try searching our database.

Newbie question.. reading location header

Thread view: 
john - 31 Dec 2005 16:25 GMT
Hi, i'm new to java, I'm trying to read the "location header" that
contains webpage redirect information from a web server.  What class do
i use? can you provide an example?  

Thanks in advance.
Rhino - 31 Dec 2005 16:57 GMT
> Hi, i'm new to java, I'm trying to read the "location header" that
> contains webpage redirect information from a web server.  What class do
> i use? can you provide an example?

That's pretty hard to answer as you've given us very little information. It
would help to know what kind of program you are writing: an applet? an
application? a servlet? a midlet? something else?

It should be fairly easy to get that information in a servlet but most Java
newbies don't start by writing servlets. Other types of Java programs may or
may not have access to that information. It's not reasonable to ask us to
list all the classes and methods that might do the job without any idea of
what you're doing.

Rhino
john - 31 Dec 2005 17:43 GMT
Hi Rhino, i'm trying to write an application.   I use the following
code:
import java.net.*;
import java.io.*;
public class Testing {

 public static void main(String[] args) {
         {
     try {
         URL u = new
URL("http://www.techbargains.com/jump.cfm?id=75&arg=retail/product.asp?sku=10330420");
         URLConnection newu = u.openConnection();
         for(int i=0;i<11;i++){
         String x=newu.getHeaderField(i);

System.out.print("--------------------------------------------"+'\n');
               System.out.println("field number: " + i);
               System.out.println(x);
                                          }

            }
     catch (IOException e) {
       System.err.println(e);
     }
   }
 }
}

The code returns some server info, but no rediect info, such as the
redirected link.  

Thanks
Thomas Hawtin - 31 Dec 2005 18:55 GMT
>           URLConnection newu = u.openConnection();

> The code returns some server info, but no rediect info, such as the
> redirected link.  

By default, it should follow the redirects to the redirected page.

http://download.java.net/jdk6/docs/api/java/net/HttpURLConnection.html#setFollow
Redirects(boolean
)

Tom Hawtin
Signature

Unemployed English Java programmer
http://jroller.com/page/tackline/

john - 31 Dec 2005 21:17 GMT
Yes, but that is not what i need.  Specifically, i need to read the
redirected link (the URL) from the server.   I was really suprised
there aren't much info out there on the internet, I have search google
and the news group, but couldn't find much anything.  

Thanks,
john - 02 Jan 2006 01:27 GMT
can somebody help??? thanks
Thomas Hawtin - 02 Jan 2006 11:45 GMT
> Yes, but that is not what i need.  Specifically, i need to read the
> redirected link (the URL) from the server.   I was really suprised
> there aren't much info out there on the internet, I have search google
> and the news group, but couldn't find much anything.  

What don't you need?

I believe I gave you a link to the method in HttpURLConnection that
controls whether redirects are followed or not.

Tom Hawtin
Signature

Unemployed English Java programmer
http://jroller.com/page/tackline/

john - 03 Jan 2006 00:11 GMT
thanks for your response Thomas,  you did give me the link to the
HttpURLConnection class, maybe i just have learn how to apply it.   You
are great help!!!
Roedy Green - 03 Jan 2006 00:35 GMT
On Mon, 02 Jan 2006 11:59:06 +0000, Thomas Hawtin
<usenet@tackline.plus.com> wrote, quoted or indirectly quoted someone
who said :

>I believe I gave you a link to the method in HttpURLConnection that
>controls whether redirects are followed or not.

If you DON'T follow redirects, you would get the web page containing
the redirect, would you not, which you could study.

Or are these redirects done without an intermediate web page?
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

john - 03 Jan 2006 07:13 GMT
I have tried to use HttpURLConnection, but still couldn't be able to
get the redirected
link(((http://www.techbargains.com/jump.cfm?id=75&arg=retail/product.asp?sku...
====>www.sitename.com/oiwoowl.....)))).   I just need the limk, not
the webpage itself.   There seem not way of doing it in Java.

thanks,
Chris Smith - 04 Jan 2006 19:10 GMT
> I have tried to use HttpURLConnection, but still couldn't be able to
> get the redirected
> link(((http://www.techbargains.com/jump.cfm?id=75&arg=retail/product.asp?sku...
>  ====>www.sitename.com/oiwoowl.....)))).   I just need the limk, not
> the webpage itself.   There seem not way of doing it in Java.

Of course there's a way of doing it in Java.  You are doing something
wrong.  I don't know what, because you've told us very little about what
you're doing in the first place.  "still couldn't be able to get the
redirected link" doesn't communicate much about how you tried to do it.  
Did you try calling getHeaderField on the HttpURLConnection after making
the request?

Signature

www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.