JavaFX - 在Chrome浏览器中打开URL

时间:2014-06-13 09:43:49

标签: javafx javafx-2 javafx-webengine

我有一个仅在Chrome浏览器下工作的网址。我在webview中打开了一个url,但它无法正常工作。我收到以下错误。所以我想在Chrome浏览器中打开它。可能吗?如果有,请帮助我。

Code
 WebView browser = new WebView();

 WebEngine webEngine = browser.getEngine();

 System.out.println(webEngine);
 webEngine.load(url);

 Scene scene = new Scene(browser);
 stage.setScene(scene);
 stage.show();

Error

Jun 13, 2014 3:43:06 PM com.sun.webpane.webkit.network.URLLoader doRun
WARNING: Unexpected error
javax.net.ssl.SSLProtocolException: Extensions not allowed in v2 certificate
    at sun.security.ssl.HandshakeMessage$CertificateMsg.<init>(HandshakeMessage.java:451)
    at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:153)
    at sun.security.ssl.Handshaker.processLoop(Handshaker.java:868)
    at sun.security.ssl.Handshaker.process_record(Handshaker.java:804)
    at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1016)
    at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1312)
    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1339)
    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1323)
    at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:515)
    at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
    at sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:153)
    at com.sun.webpane.webkit.network.URLLoader.sendRequest(URLLoader.java:322)
    at com.sun.webpane.webkit.network.URLLoader.doRun(URLLoader.java:141)
    at com.sun.webpane.webkit.network.URLLoader.access$000(URLLoader.java:44)
    at com.sun.webpane.webkit.network.URLLoader$1.run(URLLoader.java:106)
    at com.sun.webpane.webkit.network.URLLoader$1.run(URLLoader.java:103)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.webpane.webkit.network.URLLoader.run(URLLoader.java:103)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
    at java.util.concurrent.FutureTask.run(FutureTask.java:166)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:724)
Caused by: java.security.cert.CertificateParsingException: Extensions not allowed in v2 certificate
    at sun.security.x509.X509CertInfo.parse(X509CertInfo.java:736)
    at sun.security.x509.X509CertInfo.<init>(X509CertInfo.java:169)
    at sun.security.x509.X509CertImpl.parse(X509CertImpl.java:1788)
    at sun.security.x509.X509CertImpl.<init>(X509CertImpl.java:202)
    at sun.security.provider.X509Factory.engineGenerateCertificate(X509Factory.java:97)
    at java.security.cert.CertificateFactory.generateCertificate(CertificateFactory.java:339)
    at sun.security.ssl.HandshakeMessage$CertificateMsg.<init>(HandshakeMessage.java:449)
    ... 23 more

1 个答案:

答案 0 :(得分:13)

是的,您可以从Java中启动用户的默认浏览器。它可能不是Chrome。以下是使用按钮启动浏览器的示例:

Button button = new Button("Example Button");

button.setOnAction(new EventHandler<ActionEvent>() {
   @Override public void handle(ActionEvent e) {
        try {
            Desktop.getDesktop().browse(new URI("http://www.example.com"));
        } catch (IOException e1) {
            e1.printStackTrace();
        } catch (URISyntaxException e1) {
            e1.printStackTrace();
        }
        }
    }
);