2 Replies Latest reply on Oct 12, 2004 6:10 AM by 843810

    Newbie: URL AccessControlException

    843810
      Hi

      I need to be able to grab the HTML source of a webpage so I got this sample code from a tutorial for a starting point:

      import java.net.*;
      import java.io.*;

      public class Webfilter extends java.applet.Applet {

      /** Initialization method that will be called after the applet is loaded
      * into the browser.
      */
      public void init() {

      try {
      URL yahoo = new URL("http://www.yahoo.com/");

      try {
      BufferedReader in = new BufferedReader(new InputStreamReader(yahoo.openStream()));

      String inputLine;

      while ((inputLine = in.readLine()) != null)
      System.out.println(inputLine);

      in.close();
      } catch (IOException e) {

      }
      } catch (MalformedURLException e) {

      }

      }

      }

      The problem is that I get the following error:

      java.security.AccessControlException: access denied (java.net.SocketPermission www.yahoo.com resolve)
      at java.security.AccessControlContext.checkPermission(AccessControlContext.java:269)
      at java.security.AccessController.checkPermission(AccessController.java:401)
      at java.lang.SecurityManager.checkPermission(SecurityManager.java:524)
      at java.lang.SecurityManager.checkConnect(SecurityManager.java:1023)
      at java.net.InetAddress.getAllByName0(InetAddress.java:1000)
      at java.net.InetAddress.getAllByName0(InetAddress.java:981)
      at java.net.InetAddress.getAllByName(InetAddress.java:975)
      at java.net.InetAddress.getByName(InetAddress.java:889)
      at sun.net.www.http.HttpClient.<init>(HttpClient.java:296)
      at sun.net.www.http.HttpClient.<init>(HttpClient.java:267)
      at sun.net.www.http.HttpClient.New(HttpClient.java:339)
      at sun.net.www.http.HttpClient.New(HttpClient.java:320)
      at sun.net.www.http.HttpClient.New(HttpClient.java:315)
      at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:510)
      at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:487)
      at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:615)
      at java.net.URL.openStream(URL.java:913)
      at Webfilter.init(Webfilter.java:25)
      at sun.applet.AppletPanel.run(AppletPanel.java:353)
      at java.lang.Thread.run(Thread.java:534)

      Why?

      Any help will do. What permission do you need to access this page?

      Thanks
      Talib