从运行Web应用程序一个小程序时java.lang.RuntimePermission [英] java.lang.RuntimePermission when running a applet from the web application

查看:691
本文介绍了从运行Web应用程序一个小程序时java.lang.RuntimePermission的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从一个小程序读取环境不受varaible,这里是我的code

I'm trying to read a envrionment varaible from a applet, here is my code

    String env = System.getenv("TWS");
    System.out.println(env);
    Runtime rt = Runtime.getRuntime();
    String s = env + "\\WebStart.bat " ;
    System.out.println(s);
    try {
        Process p = rt.exec(s);
    } catch (Exception e) {
    }

当我运行通过右键单击并运行NetBeans的code,它正在运行没有问题。

when i run the code from netbeans by right click and run, it is running without a problem.

但是当我把它放到一个jar文件,将其添加到我的web应用程序,并尝试使用以下code从HTML页面运行它

but when i put it to a jar file, add it to my web application and try to run it from a html page using the following code

<applet code="draw.class" archive='AppletTest.jar'>
   <param name="shape" value="triangle"/>
</applet>

我得到一个错误说的拒绝访问,java.lang.RuntimePermission

我运行使用Tomcat 6这个Web应用程序。

i am running this web application using tomcat 6.

我看过一些指导,并添加下面进入catalina.policy里在Tomcat中6文件并重新启动Tomcat的

i have read some guides and added the following entry to catalina.policy file in tomcat 6 and restarted tomcat

permission java.lang.RuntimePermission "accessDeclaredMembers";

但还是同样的警告。可有一个人请提出这个问题的解决方案?

but still the same warning. can some one please suggest a solution for this problem?

- rangana

--rangana

推荐答案

当您运行从NetBeans中您的小程序,Java虚拟机上运行它,当你通过浏览器来运行它比一个不同的安全制度之下。

When you run your applet from netbeans, Java virtual machines runs it under a different security regime than when you run it through browser.

小程序,通过浏览器下载的,未使用安全证书签名,被认为是不可信的和被称为未签名的Applet。当一个客户端上运行,未签名的Applet的安全沙箱,只允许一组安全运行的范围内运作。您可以检查是否perticular权限授予您的applet或不使用的的SecurityManager 。例如,在你的情况:

Applets, downloaded through browsers, that are not signed using a security certificate, are considered to be untrusted and referred to as unsigned applets. When running on a client, unsigned applets operate within a security sandbox that allows only a set of safe operations. You can check if a perticular permission is granted to you applet or not by using SecurityManager. For example in your case :

System.getSecurityManager().checkPermission(new RuntimePermission("accessDeclaredMembers"));

您可以了解更多关于小程序安全性的 这里 这里 。在制作签名的Applet一个很不错的教程可以发现此处

You can know more about applet security here and here. A very nice tutorial on making signed applets can be found here.

这篇关于从运行Web应用程序一个小程序时java.lang.RuntimePermission的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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