Failing to retrieve the WEBpage

Hi,

I want to get a Webpage back thru my java code...but its getting some exceptions and not really working...

*/

public class Urlconn {

public static void main(String args[]){

try{

URL url=new URL("http://java.sun.com");

URLConnection conn=url.openConnection();

BufferedReader in=new BufferedReader(new InputStreamReader(conn.getInputStream()));

String inputLine;

while((inputLine=in.readLine())!=null)

System.out.println(inputLine);

in.close();

}catch(Exception e){

e.printStackTrace();

}

}

}

can anyone please help ?The error its showing is socket connect exception..

java.net.ConnectException: Connection refused: connect

at java.net.PlainSocketImpl.socketConnect(Native Method)

at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)

at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)

at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)

at java.net.Socket.connect(Socket.java:507)

at java.net.Socket.connect(Socket.java:457)

at sun.net.NetworkClient.doConnect(NetworkClient.java:157)

at sun.net.www.http.HttpClient.openServer(HttpClient.java:365)

at sun.net.www.http.HttpClient.openServer(HttpClient.java:477)

at sun.net.www.http.HttpClient.<init>(HttpClient.java:214)

at sun.net.www.http.HttpClient.New(HttpClient.java:287)

at sun.net.www.http.HttpClient.New(HttpClient.java:299)

at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:792)

at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:744)

at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:669)

at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:913)

[1907 byte] By [profilemia] at [2007-11-27 4:48:50]
# 1
Try to use a concrete path name like http://java.sun.com/index.jsp and set the proxy if available.Sincerely Christian Ullenboom | http://www.tutego.com/
Christian.Ullenbooma at 2007-7-12 10:01:49 > top of Java-index,Core,Core APIs...
# 2
yes grt thnx..i can retrive the page now...but teh issue is I want to get it in HTML format itself...not as an array of characters..can u let me know wat shud i do?
profilemia at 2007-7-12 10:01:49 > top of Java-index,Core,Core APIs...
# 3
ummm....what?!And what is HTML if not text ie. 'an array of characters'?!! If you want an HTML file, you write those charcters to a file, if you want something specific out of it, you parse it in an apropriate fashion.What were you trying to do anyway?
jadespirita at 2007-7-12 10:01:49 > top of Java-index,Core,Core APIs...
# 4

okkk...

Wat i want to mean is that I want to open the page in a browser...My intention is not only to get the webpage html source code in my inputstream...i want to display teh webpage itself in a browser when i execute this code with all its images and watsoever...Can you suggest please how shud i proceed?

profilemia at 2007-7-12 10:01:49 > top of Java-index,Core,Core APIs...
# 5
If I got you correctly, you just want to start the browser and direct it to the desired URL, right? If that's the case, all you need to do is use 1.6 desktop api, namelydesktop.browse(uri)method.
jadespirita at 2007-7-12 10:01:49 > top of Java-index,Core,Core APIs...
# 6
hi , In which package do i get the desktop class?
profilemia at 2007-7-12 10:01:49 > top of Java-index,Core,Core APIs...
# 7
Hmmm... I thought it would be an easy thing to find....Anyway, it's: java.awt.DesktopAs I said, you'll need Java 1.6 to use this, but you could aslo download jdic if you for some reason need to work on 1.5 or older.
jadespirita at 2007-7-12 10:01:49 > top of Java-index,Core,Core APIs...
# 8
yes i am using 1.5 and i tried to Fix imports ,but could not get it,anyway thanks for ur grt help..
profilemia at 2007-7-12 10:01:49 > top of Java-index,Core,Core APIs...