【问题标题】:Getting a SecurityException: Permission denied in java获取 SecurityException:Java 中的权限被拒绝
【发布时间】:2012-03-06 13:54:32
【问题描述】:

当我尝试使用小程序时,我收到了java.lang.SecurityException: Permission denied: file:////Videos/public/scripts/screenshot.jar

这是小程序代码:

<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);

     }

} 

【问题讨论】:

  • 您很有可能只需要sign the applet
  • 我必须为每个小程序都这样做吗?这些工具是否已经安装(如 keytool)
  • “有人能解释一下..这是怎么做到的吗?” 你在使用 IDE 吗?如果有,是哪一个?

标签: java html applet securityexception


【解决方案1】:

这完全取决于您的小程序试图做什么,例如它是否访问文件系统。它是签名的小程序吗?默认情况下,Applet 在一个特殊的沙箱中运行,具有有限的权限。 您必须查看有关 Applet 安全性的更多信息,初学者可以在此处查看 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?

【讨论】:

  • 您是在某个 IDE 中开发它吗?如果是,是哪一个?你可以发布代码吗?把项目放到github上?换句话说,我向我们展示了一些代码。
猜你喜欢
  • 2014-06-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-06-11
  • 2015-08-30
相关资源
最近更新 更多