本文介绍了提供一个备用的Applet安全例外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个需要与一些特权运行,这意味着在加载时会显示警告信息的小程序。如果用户拒绝警告消息,我想重定向到一个错误页面,并解释发生了什么。有没有办法做到这一点?

我看着于具有定时器运行,在一定时间后重定向但是这并不准确,这将是很好赶上从弹出的反应吧。

如果用户拒绝警告下抛出异常:

  java.lang.SecurityException异常:尝试打开沙盒罐[JAR文件]
    作为一个可信库

唯一的例外是达到初始化函数之前抛出。


解决方案

..extend that to add a JS function that cancels the timer, then call that JS from the applet, is about the best protection you can get.

A try/catch on security related matters can work for some JREs that load applet sand-boxed if the security prompt is refused, but other run-times (notably the Iced Tea JRE) will not load the applet at all if the security prompt is refused.

If the user can be guaranteed to have a 'Next Generation' - Plug-In 2 JRE (mentioned in the applet info. page), it is possible to the use the JNLP API in an embedded applet. The JNLP services provide access to the local disks for a sand-boxed app. See this demo of the JNLP file services.

But there is a slight hitch. There is no option to persist the path to the file chosen by the user. In this lesser security environment, the JRE does not provide a File but instead a JNLP API FileContents object. It will not provide a path and is not serializable. But if the user is willing to choose the file each run, it could be workable.


..and that reminds me. Perhaps a better alternative for launching trusted apps. is to offer a free-floating (applet or) frame using Java Web Start. If the user refuses, it never appears on-screen, but they can click the launch button again any time they like (to be prompted again).

这篇关于提供一个备用的Applet安全例外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 01:46
查看更多