问题描述
我已经写了我的第一个 Java 小程序.
I have wrote my first java applet.
它基本上从我的 Django 网络服务器加载一些图像,然后用户可以修改它们.
It basically loads some images from my Django webserver and then the user can modify them.
我在 Eclipse 中开发它,我完全没有问题.当我用测试页尝试它时,在 java 控制台上出现此错误:
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)
被指控的一段代码:
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.
提前致谢.
推荐答案
除非小程序已签名,否则它将无法访问位于原始服务器之外的其他位置的图像.在这里你可以使用:
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);
这篇关于Java Applet 无法从网络加载图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!