[英]Problems with Applet in Website (AccessControlException)
因此,當我嘗試從我的網站加載小程序時,我得到了
AccessControlException
access denied ("java.io.FilePermission" "cursor.gif" "read")
這對應於我的applet中的代碼。
//Modify the cursor when inside the Applet
Toolkit toolkit = Toolkit.getDefaultToolkit();
Image cursorIcon = toolkit.getImage("cursor.gif");
Point center = new Point(16, 16);
Cursor cursor = toolkit.createCustomCursor(cursorIcon, center, "Cursor");
setCursor(cursor);
我已經用谷歌搜索並嘗試了諸如
.jar
簽名 當我在eclipse中運行它時,我的applet可以很好地工作。此外,如果我注釋掉上面的代碼,我的applet可以正常工作,因此該部分給我一個錯誤。
您必須將代碼包裝在特權代碼中,例如:
final String location = locationVal;
File f = (File) AccessController.doPrivileged(new PrivilegedAction()
{
public Object run()
{
System.out.println("Getting File : " + location);
File outputFile1 = new File(location);
return outputFile1;
}
});
這段代碼是從以下位置復制的: 需要客戶端權限才能訪問資源的我的applet的策略文件位置在哪里?
也有用的鏈接:
關於Java政策實施的http://docs.oracle.com/javase/6/docs/technotes/guides/security/PolicyFiles.html 。
http://docs.oracle.com/javase/1.3/docs/tooldocs/win32/policytool.html#使用GUI策略文件編輯器的用法
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.