AccessControlException or ClassCastException when trying to use httpURLConnection within an Applet
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   shiela_dixon
Posted On:   Monday, October 29, 2001 01:36 AM

Is it possible for an Applet to access the content of HTML pages? I've been writing a little link walker (you know the kind of thing - looks through the content of an HTML page, extracts links, checks them and follows any in the same site) which is running well when compiled and run as an Applet (locally) using the applet runner or certain browsers on my Mac. However, when I try to run it over the internet or on any browser on a PC I get either an AccessControlException or a ClassCastException at the point that it tries to make the httpurlconnection. Here's a precis version of the relevant fragment: public String getContent(String page){ String output = new String(""); String inputLin   More>>

Is it possible for an Applet to access the content of HTML pages?


I've been writing a little link walker (you know the kind of thing - looks through the content of an HTML page, extracts links, checks them and follows any in the same site) which is running well when compiled and run as an Applet (locally) using the applet runner or certain browsers on my Mac. However, when I try to run it over the internet or on any browser on a PC I get either an AccessControlException or a ClassCastException at the point that it tries to make the httpurlconnection.


Here's a precis version of the relevant fragment:



public String getContent(String page){

String output = new String("");

String inputLine;

String strPageContent = new String("");

URL url;

HttpURLConnection connection;



String ct, ce;

InputStreamReader in;

BufferedReader reader;



try{

url = new URL(page);

connection = (HttpURLConnection)url.openConnection();



connection.setRequestMethod("GET");



in = new InputStreamReader(connection.getInputStream());

reader = new BufferedReader(in);



connection.connect();



while((inputLine = reader.readLine())!=null){

strPageContent = strPageContent+inputLine+"
";

}

in.close();

}




Is it possible for an Applet to access HTML pages in this way? Is there another way for my applet to read the contents of a page? (I'd really like to make this client side rather than server side)


Any help appreciated!


Shiela

   <<Less
About | Sitemap | Contact