1

Java 6u13 和 6u14 中有一个错误。 http://bugs.sun.com/view_bug.do?bug_id=6835450

简单地说,下面的代码应该打开一个浏览器窗口,但是由于框架中的一个错误,它在 Java 1.6 update 13 中停止工作。不再打开任何东西。Java 小程序有一个类似的错误(已在更新 14 中修复),但这个错误仍然存​​在于 Java WebStart/JNLP 的更新 14 中。

getAppletContext().showDocument(new URL("http://www.sun.com"),"_blank");

您知道任何解决方法吗?

4

3 回答 3

4

我没有在 JNLP 中尝试过,但通常这应该可以工作:

java.awt.Desktop.getDesktop().browse(new URI("http://www.sun.com"));
于 2009-07-13T14:09:32.123 回答
0

BasicService.showDocument行得通吗?我不记得这是如何实现的。

或者,使用 LiveConnect 自己执行 JavaScript(尽管这可能会遇到同样的问题)。

于 2009-07-13T14:13:34.397 回答
0
public boolean openUrl(final URL url) {
    try {
        // Lookup the javax.jnlp.BasicService object
        BasicService bs = (BasicService)javax.jnlp.ServiceManager.lookup("javax.jnlp.BasicService");
        // Invoke the showDocument method
        return bs.showDocument(url);
    } catch(UnavailableServiceException ue) {
        // Service is not supported
        log.log(Level.WARNING, "Could not open URL " + url, ue);
        return false;
    }       
}
于 2010-02-19T18:54:15.900 回答