0

I have wrote my first java applet.

It basically loads some images from my Django webserver and then the user can modify them.

I developed it in Eclipse, and I had no problems at all. When I tried it with a test page, on the java console come out this error:

java.security.AccessControlException: access denied (java.net.SocketPermission www.hyros.net resolve)
    at java.security.AccessControlContext.checkPermission(AccessControlContext.java:374)
    at java.security.AccessController.checkPermission(AccessController.java:546)
    at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
    at java.lang.SecurityManager.checkConnect(SecurityManager.java:1031)
    at sun.plugin2.applet.Applet2SecurityManager.checkConnect(Applet2SecurityManager.java:500)
    at sun.plugin2.applet.Plugin2Manager$AppletContextImpl.getImage(Plugin2Manager.java:2718)
    at java.applet.Applet.getImage(Applet.java:242)
    at MapGenerator.getResourceImage(MapGenerator.java:50)
    at MapGenerator.init(MapGenerator.java:35)
    at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Plugin2Manager.java:1637)
    at java.lang.Thread.run(Thread.java:662)
Eccezione: java.security.AccessControlException: access denied (java.net.SocketPermission www.hyros.net resolve) 

The incriminated piece of code:

for(int i=0; i< numero_immagini; i++) {
    try {
        URL url = new URL(this.getParameter(IMMAGINE+i));
        images[i] = ImageIO.read(url);
        floors[i] = Integer.parseInt(this.getParameter(PIANO_IMMAGINE+i));
    } catch (IOException ioe) {ioe.printStackTrace();}
}

For the test i tried an image from my local webserver, but the error comes out with every possible link, internal or external.

Thank you in advance.

Marco Fedele
  • 2,090
  • 2
  • 25
  • 45
  • duplicate: http://stackoverflow.com/questions/4169717/why-does-my-applet-get-a-java-security-accesscontrolexception-access-denied-ja?rq=1 – guido Sep 27 '12 at 15:19

2 Answers2

0

Ok, Solved it!

The line of code to change is

URL url = new URL(this.getParameter(IMMAGINE+i));

to

URL url = new URL(getCodeBase(), this.getParameter(IMMAGINE+i));
Marco Fedele
  • 2,090
  • 2
  • 25
  • 45
0

Unless the applet is signed, it will not be able to access images at a different location other then that of the originating server. Here you could use:

images[i] = getImage(getDocumentBase(), IMMAGINE + i);
Reimeus
  • 158,255
  • 15
  • 216
  • 276
  • I forgot to mention it!!! For the code, I prefer to edit only the URL, because in the rest of the app I work with BufferedImage. – Marco Fedele Sep 27 '12 at 23:22