获取一个SecurityException:权限在java中被拒绝 [英] Getting a SecurityException: Permission denied in java

查看:602
本文介绍了获取一个SecurityException:权限在java中被拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到 java.lang.SecurityException异常:权限被拒绝:文件:////Videos/public/scripts/screenshot.jar 当我尝试使用小程序。

下面是小程序code:

 <小程序code =屏幕截图档案=文件:////Videos/public/scripts/screenshot.jarWIDTH =100px的HEIGHT = 100px的>
< /小程序>

如何解决呢,什么问题,甚至手段?

编辑:

从我看到我需要签名Applet。可能有人解释如何以及为什么这样做?提供的网站确实做得不好解释它,因为它甚至不解决,我嵌入到我的网站这个事实,并希望每一个客户端来使用它,而不必签署任何东西。只需点击运行。

EDIT2:

在应用程序本身的code:

  / *
通过Bavo Bruylandt(Http://www.realapplets.com)* ///现在inevidable的Hello World的例子:)//告诉编译器在哪里可以找到您要使用的方法。
//当你创建一个小程序所需
导入的java.applet。*;
//需要画上屏幕
进口java.awt中的*。
//一个小程序的启动 - 的HelloWorld将是可执行的类
//扩展小程序意味着你将建立code对标准的Applet类
公共类截图扩展的Applet
{//将当小程序开始自动调用的方法
     公共无效的init()
     {
 //这是必需的,但并不需要什么。
     }
//此方法被当小程序被终止叫
//当用户进入到另一个页面或退出浏览器。
     公共无效停止()
     {
     //现在需要在这里没有动作。
     }
//你有标准的方法,用油漆在屏幕上的东西
//这将覆盖空Applet的方法,你不能把它称为显示器为例。     公共无效漆(图形G)
     {
 //方法在屏幕上绘制文本
 //串首先,则x和y坐标。
      g.drawString(嘿嘿嘿,20,20);
      g.drawString(Hellooow世界,20,40);     }}


解决方案

这一切都取决于你有什么小程序试图做的,它是访问,例如文件系统。它是一个签名的applet或不?小程序在一个特殊的沙箱默认情况下,有限的权限运行。
你将不得不签出更多的信息上的Applet的安全性,对于初学者看看到InformIT的文章在这里:的 http://www.informit.com/articles/article.aspx?p=433382&seqNum=2

编辑:

尝试添加一个策略文件如:

  / *自动生成于星期二2002年4月16日17点20分59秒EDT * /
  / * DO NOT EDIT * /   补助{
     权限java.security.AllPermission;
   };

命名如。 java.policy.applet并将其放置在你的类路径中。看看这个问题,在这里对政策文件:在哪里放置Java applet的政策文件?

I am getting the java.lang.SecurityException: Permission denied: file:////Videos/public/scripts/screenshot.jar when I try to use an applet.

Here is the applet code:

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

How do I fix it and what the problem even means?

EDIT:

From what I see I need to sign the applet. Could some one explain how and why this is done? The site provided does a bad job explaining it because it doesn't even address the fact that I am embedding this into my site and want every client to use it and not have to sign anything. Just click run.

EDIT2:

The code of the app itself:

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

     }

} 

解决方案

It all depends on what is your applet trying to do, is it accessing the filesystem for example. Is it a signed applet or not? Applets run in a special sandbox by default with limited permissions. You would have to check out more info on Applet security, for starters have a look into Informit article here: http://www.informit.com/articles/article.aspx?p=433382&seqNum=2

EDIT:

Try to add a policy file eg.

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

   grant {
     permission java.security.AllPermission;
   };

named eg. java.policy.applet and place it on your classpath. Have a look at this question here about the policy files: Where to place java applet policy file?

这篇关于获取一个SecurityException:权限在java中被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆