在JRE1.4.2以上版本中解决Javascript调用已签名Applet方法时提示没有权限问题

在JRE1.4.2以上版本中,如果是javascript掉用Applet方法时,即使用户已经信任了这个Applet的签名,还是有可能会出现权限不够的问题,但是如果Applet自己调用方法则没有问题,为此,可以在Applet中的start方法中启动一个线程,这个线程有足够的权限,然后在javascript方法中和这个线程进行交互,以下是代码

public class MyApplet extends Applet {
  Thread thread;
  String command;
  Object result;
  boolean isEnd = false;

  public void start(){
    thread = new Thread(new Runnable() {
      public void run(){
        while(!isEnd){
          try{
            synchronized(thread){
              thread.wait();
            }
          }catch(Exception e){e.printStackTrace();}
          if(isEnd) return;
          try{
            if(“CallExe“.equals(command))
                result = callExe();
          }catch(Exception e){e.printStackTrace();}
          synchronized(CardApplet.this){
            CardApplet.this.notify();
          }
        }
      }
    });
    thread.start();
  }

  public void stop(){
    isEnd = true;
    synchronized(thread){
      thread.notify();
    }
  }

  String call(){
    this.command = “CallExe“;
    try{
      synchronized(thread){
        thread.notify();
      }
      synchronized(this){
        wait();
      }
    }catch(Exception e){
      e.printStackTrace();
    }
    return result;
  }

String callExe(){
    //todo add logic here
    return null;
  }

}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值