473,386 Members | 1,644 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

HEllppp

import java.io.*;
import java.net.*;
public class aaa{
public aaa() {
}
public boolean visitWebPage(String UrlToVisit) {
boolean urlVisited = false;
try {
java.net.URL url = new java.net.URL(UrlToVisit);
java.net.URLConnection urlConnection = url.openConnection();
BufferedReader htmlPage = new BufferedReader(new InputStreamReader(url.openStream()));
String line = "";
while((line = htmlPage.readLine()) != null) {
System.out.println("hi");
System.out.println(line);
}
htmlPage.close();
urlConnection = null;
urlVisited = true;
} catch(Exception e) {
urlVisited = false;
}
return urlVisited;
}
public static void main(String[] args) {
aaa urlVisit = new aaa();
String url = null;
String commstart = " <!-- *********************** ";
String commend = " *********************** -->";
url ="http://www.yahoo.com" ;
System.out.println(commstart + "Visiting "+ url + commend);
if (urlVisit.visitWebPage(url)) {
System.out.println(commstart + url + " visited" + commend);
} else {
System.out.println(commstart + url + " Website not found" +commend);
}
}
}

I am trying to check whether the specified website is visited or not...but i am not able to establish a connection ..else part is displayed all the time helpp me out...
waiting for ur replies..
Sep 28 '06 #1
2 1236
r035198x
13,262 8TB
import java.io.*;
import java.net.*;
public class aaa{
public aaa() {
}
public boolean visitWebPage(String UrlToVisit) {
boolean urlVisited = false;
try {
java.net.URL url = new java.net.URL(UrlToVisit);
java.net.URLConnection urlConnection = url.openConnection();
BufferedReader htmlPage = new BufferedReader(new InputStreamReader(url.openStream()));
String line = "";
while((line = htmlPage.readLine()) != null) {
System.out.println("hi");
System.out.println(line);
}
htmlPage.close();
urlConnection = null;
urlVisited = true;
} catch(Exception e) {
urlVisited = false;
}
return urlVisited;
}
public static void main(String[] args) {
aaa urlVisit = new aaa();
String url = null;
String commstart = " <!-- *********************** ";
String commend = " *********************** -->";
url ="http://www.yahoo.com" ;
System.out.println(commstart + "Visiting "+ url + commend);
if (urlVisit.visitWebPage(url)) {
System.out.println(commstart + url + " visited" + commend);
} else {
System.out.println(commstart + url + " Website not found" +commend);
}
}
}

I am trying to check whether the specified website is visited or not...but i am not able to establish a connection ..else part is displayed all the time helpp me out...
waiting for ur replies..
if you just want to visit a page, look at this

Expand|Select|Wrap|Line Numbers
  1. public class aaa {
  2.             public static void main(String[] args) {
  3.             String browserPath = "C:/Program Files/Internet  Explorer/IEXPLORE.EXE"; //Use your browser path
  4.                 String url = "www.sun.com";
  5.                 try {
  6.          String[] b = {browserPath, url};
  7.                      Runtime.getRuntime().exec(b);
  8.                 }
  9.                 catch (Exception exc) {
  10.     exc.printStackTrace();
  11.                 }
  12.     }
  13. }
Sep 28 '06 #2
if you just want to visit a page, look at this

Expand|Select|Wrap|Line Numbers
  1. public class aaa {
  2.             public static void main(String[] args) {
  3.             String browserPath = "C:/Program Files/Internet  Explorer/IEXPLORE.EXE"; //Use your browser path
  4.                 String url = "www.sun.com";
  5.                 try {
  6.          String[] b = {browserPath, url};
  7.                      Runtime.getRuntime().exec(b);
  8.                 }
  9.                 catch (Exception exc) {
  10.     exc.printStackTrace();
  11.                 }
  12.     }
  13. }

Thanks for the code but i dont want the user to know which website it is visited
i dont want a browser to open a url..
Sep 28 '06 #3

Sign in to post your reply or Sign up for a free account.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.