title: access denied (java.net.SocketPermission 127.0.0.1:8080 connect,resolve)
body: <p>I have a Java Applet inserted on a simple HTML page located at <a href="http://localhost:8080/index.html" rel="noreferrer">http://localhost:8080/index.html</a>:</p>
  
  <pre><code>&lt;applet id="applet" code="SomeCode.class" archive="lib.jar" Width="1" Height="1"&gt;&lt;/applet&gt;
  </code></pre>
  
  <p>The Java Applet has a method that looks similar to the code below:</p>
  
  <pre><code>public void PostStuffToServer() {
    String server = "http://localhost:8080/PostHandler.ashx";
    URL u = new URL(server);
    URLConnection con = u.openConnection();
    con.setDoOutput(true);
    con.getOutputStream().write(stream.toByteArray());
    con.connect();
  }
  </code></pre>
  
  <p>When I execute the applet code from JavaScript like so:</p>
  
  <pre><code>obj = document.getElementById('applet');
  obj.getClipboardImageURL();
  </code></pre>
  
  <p>I get the following error:</p>
  
  <p><em>access denied (java.net.SocketPermission 127.0.0.1:8080 connect,resolve)</em></p>
  
  <p>It seems like the Java code resolves the domain <em>localhost</em> to its equivalent IP address and therefore raises a cross domain security restrain. It works fine when I execute the same code from <a href="http://127.0.0.1:8080/index.html" rel="noreferrer">http://127.0.0.1:8080/index.html</a>. The lib.jar file is signed.</p>
  
  <p>Is there anyway to avoid this?</p>