0

经过数小时的工作(我不是 Java 程序员),我设法打包并放入一个小程序,以便将 ftp 上传到远程服务器。主文件是“invia.jar”中的“prova.class”;我使用第三方库,放在“edtftpj.jar”中。我已经签署了这两个文件并将它们包含在页面中,代码如下:

索引.html

<applet width="300" height="300"  classpath="./" code="prova.class" archive="invio.jar,edtftpj.jar"> </applet>

现在,当我将浏览器指向我的页面时,我在控制台上发现了这条消息:

Could not read property 'edtftp.log.level' due to security permissions
Could not read property 'edtftp.log.log4j' due to security permissions
Could not read property 'edtftp.log.log4j' due to security permissions
java.security.AccessControlException: access denied (java.net.SocketPermission www.artkiller-web.com resolve)
 at java.security.AccessControlContext.checkPermission(Unknown Source)
 at java.security.AccessController.checkPermission(Unknown Source)
 at java.lang.SecurityManager.checkPermission(Unknown Source)
 at java.lang.SecurityManager.checkConnect(Unknown Source)
 at sun.plugin2.applet.Applet2SecurityManager.checkConnect(Unknown Source)
 at java.net.InetAddress.getAllByName0(Unknown Source)
 at java.net.InetAddress.getAllByName(Unknown Source)
 at java.net.InetAddress.getAllByName(Unknown Source)
 at java.net.InetAddress.getByName(Unknown Source)
 at com.enterprisedt.net.ftp.FTPClient.connect(FTPClient.java:966)
 at com.enterprisedt.net.ftp.FileTransferClient.connect(FileTransferClient.java:386)
 at prova.start(prova.java:44)
 at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
 at java.lang.Thread.run(Unknown Source)

关于如何解决的任何想法?

提前谢谢你

啤酒

4

1 回答 1

1

您需要将连接 url 包装在特权代码块中。

看起来您在从属性文件中读取时遇到问题,您可以将属性文件打包在您的 jar 中,如果您尝试从客户端计算机读取属性文件,则需要将该代码包装在特权代码块中出色地。

这是我在另一个答案中用于通过访问控制器获取 URL 的代码块。

 try 
 {
     final String imageURL = "http://www.google.com/intl/en_ALL/images/logo.gif";
     URL url = (URL) AccessController.doPrivileged(new PrivilegedAction() 
     {

         public Object run() 
         {
             try
             {
               return new URL(imageURL);
             }
             catch (MalformedURLException e)
             {
               e.printStackTrace();
               return null;
             }

        }  
      });  

     if(url == null)
     {
        // Something is wrong notify the user
     }
     else
     {
        // We know the url is good so continue on
         img = ImageIO.read(url);
     }

  } 
  catch (IOException e) 
  {
   System.out.println(e);
  }  
于 2010-07-12T17:04:44.380 回答