JavaFX2.0 webview无法呈现页面? [英] JavaFX2.0 webview not rendering the page?

查看:549
本文介绍了JavaFX2.0 webview无法呈现页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在JavaFX2.0中编写了以下代码

I have written the following code in JavaFX2.0

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javafx.stage.Stage;

/**
 *
 * @author roger
 */
public class WebViewDemo extends Application {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) {

        StackPane root = new StackPane();
        WebView x = new WebView();
        WebEngine ex = x.getEngine();
        ex.load("http://www.google.com");
        root.getChildren().add(x);
        Scene scene = new Scene(root, 300, 250);

        primaryStage.setTitle("Hello World!");
        primaryStage.setScene(scene);
        primaryStage.show();
    }
}

我收到以下错误,但我无法弄清楚出了什么问题?

I am getting the following error and am not able to figure out what went wrong ?

Jul 03, 2012 11:18:42 PM com.sun.webpane.webkit.network.URLLoader doRun
WARNING: Unexpected error
java.lang.IllegalArgumentException: Illegal cookie name
    at java.net.HttpCookie.<init>(HttpCookie.java:158)
    at java.net.HttpCookie.parseInternal(HttpCookie.java:964)
    at java.net.HttpCookie.parse(HttpCookie.java:215)
    at java.net.HttpCookie.access$100(HttpCookie.java:58)
    at java.net.HttpCookie$12.parse(HttpCookie.java:1096)
    at sun.net.www.protocol.http.HttpURLConnection.filterHeaderField(HttpURLConnection.java:2605)
    at sun.net.www.protocol.http.HttpURLConnection.getFilteredHeaderFields(HttpURLConnection.java:2642)
    at sun.net.www.protocol.http.HttpURLConnection.getHeaderFields(HttpURLConnection.java:2686)
    at com.sun.webpane.webkit.network.URLLoader.extractHeaders(URLLoader.java:776)
    at com.sun.webpane.webkit.network.URLLoader.willSendRequest(URLLoader.java:574)
    at com.sun.webpane.webkit.network.URLLoader.doRun(URLLoader.java:155)
    at com.sun.webpane.webkit.network.URLLoader.access$000(URLLoader.java:42)
    at com.sun.webpane.webkit.network.URLLoader$1.run(URLLoader.java:104)
    at com.sun.webpane.webkit.network.URLLoader$1.run(URLLoader.java:101)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.webpane.webkit.network.URLLoader.run(URLLoader.java:101)
    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:1110)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at java.lang.Thread.run(Thread.java:722)

请让我知道需要修改什么以及出了什么问题?

please let me know what needs to be modified and what went wrong ?

推荐答案

我找到了一些google-fu < a href =https://forums.oracle.com/forums/thread.jspa?threadID=2324092\"rel =nofollow>此论坛帖子导致此错误 RT-15676 。该帖子建议添加以下行:

Some google-fu I found this forum post that led to this bug RT-15676. The post suggested adding the line:

java.net.CookieHandler.setDefault(null);

在应用程序启动之后但在启动WebView之前。所以我在将根StackPane添加到场景之前放置它。它现在似乎有效。

after the application starts but before starting the the WebView. So I placed it just before adding the root StackPane to the scene. And it seems to work now.

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javafx.stage.Stage;

public class WebViewDemo extends Application {
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) {

        StackPane root = new StackPane();
        WebView x = new WebView();
        WebEngine ex = x.getEngine();
        ex.load("http://www.google.com");

        root.getChildren().add(x);
        java.net.CookieHandler.setDefault(null);
        Scene scene = new Scene(root, 300, 250);

        primaryStage.setTitle("Hello World!");
        primaryStage.setScene(scene);
        primaryStage.show();
    }

}

这篇关于JavaFX2.0 webview无法呈现页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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