经过几个小时的工作(我不是java程序员),我成功地将程序打包并放入applet中,并将ftp上传到远程服务器。主文件是"prova.class“中的"invia.jar";我使用一个第三方库,放在"edtftpj.jar”中。我已经对这两个文件进行了签名,并将它们包含在页面中,代码如下:
Index.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)知道该怎么做吗?
提前谢谢你
ArtoAle
发布于 2010-07-12 17:04:44
您需要将连接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);
} https://stackoverflow.com/questions/3182349
复制相似问题