2012-02-15 137 views
0

我在嘗試使用小程序時遇到了java.lang.SecurityException: Permission denied: file:////Videos/public/scripts/screenshot.jar獲取SecurityException:Java中的權限被拒絕

這裏是applet代碼:

<applet code="Screenshot" archive="file:////Videos/public/scripts/screenshot.jar" width="100px" height="100px"> 
</applet> 

如何解決呢,什麼問題,甚至手段?

編輯:

從我看到我需要簽署的小程序。有人能解釋這是如何以及爲什麼這樣做的?該網站提供的解釋不好,因爲它甚至沒有解決這個事實,即我將其嵌入到我的網站中,並希望每個客戶端都使用它,而不必簽署任何內容。只需點擊運行。

EDIT2:

/* 
By Bavo Bruylandt (Http://www.realapplets.com") 

*/ 

// and now The inevidable "Hello World" example :) 

// tell the compiler where to find the methods you will use. 
// required when you create an applet 
import java.applet.*; 
// required to paint on screen 
import java.awt.*; 


// the start of an applet - HelloWorld will be the executable class 
// Extends applet means that you will build the code on the standard Applet class 
public class Screenshot extends Applet 
{ 

// The method that will be automatically called when the applet is started 
    public void init() 
    { 
// It is required but does not need anything. 
    } 


// This method gets called when the applet is terminated 
// That's when the user goes to another page or exits the browser. 
    public void stop() 
    { 
    // no actions needed here now. 
    } 


// The standard method that you have to use to paint things on screen 
// This overrides the empty Applet method, you can't called it "display" for example. 

    public void paint(Graphics g) 
    { 
//method to draw text on screen 
// String first, then x and y coordinate. 
     g.drawString("Hey hey hey",20,20); 
     g.drawString("Hellooow World",20,40); 

    } 

} 
+0

您很有可能只需[簽署applet](http://java.sun.com/developer/onlineTraining/Programming/JDCBook/signed的.html)。 – 2012-02-15 08:05:25

+0

我是否必須爲每個小程序執行此操作?那些已經安裝的工具(如keytool) – Vadiklk 2012-02-15 08:17:26

+0

還有一些可以閱讀:[Applets可以做什麼和不可以做什麼](http://docs.oracle.com/javase/tutorial/deployment/applet/security.html) – 2012-02-15 08:32:40

回答

0

這一切都取決於你有什麼小程序試圖做的,是它訪問例如文件系統:

應用程序本身的代碼。它是否是已簽名的applet?默認情況下,Applets在特殊的沙箱中運行,並且權限有限。 你將不得不簽出更多的信息上的小程序的安全性,對於初學者看看到InformIT的文章在這裏:http://www.informit.com/articles/article.aspx?p=433382&seqNum=2

編輯:

嘗試添加策略文件如。

/* AUTOMATICALLY GENERATED ON Tue Apr 16 17:20:59 EDT 2002*/ 
    /* DO NOT EDIT */ 

    grant { 
    permission java.security.AllPermission; 
    }; 

命名爲例如。 java.policy.applet並將其放置在您的類路徑中。在這裏查看關於策略文件的這個問題:Where to place java applet policy file?

+0

這是你好世界小應用程序 – Vadiklk 2012-02-15 08:16:54

+0

你在一些IDE中開發它嗎?如果是的,哪一個?你能發佈代碼嗎?把項目放在github上?我用其他的詞給我們展示了一些代碼 – Kris 2012-02-15 08:23:41

+0

編輯該問題 – Vadiklk 2012-02-15 08:26:32