Java小程序不能加载从网页图片 [英] Java Applet can't load images from web

查看:170
本文介绍了Java小程序不能加载从网页图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经写了我的第一个Java程序。

I have wrote my first java applet.

基本上,它从我的Django的web服务器加载一些图像,然后用户可以对其进行修改。

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) 

在一块牵连code的:

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.

感谢您提前。

推荐答案

除非小程序签名,将无法在其他不同的位置来访问图像,然后发端服务器。在这里,你可以使用:

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小程序不能加载从网页图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆