【问题标题】:webview with javaFX带有 javaFX 的网页视图
【发布时间】:2019-02-11 12:17:57
【问题描述】:

大家好,我试图通过 java fx web 视图访问我的计算机中的网络应用程序:

public void start(Stage stage) throws Exception {
    WebView webView = new WebView();
    WebEngine engine = webView.getEngine();

    engine.load("172.0.0.0://HOWEB/documentation:8080");//loadContent("<html> href = C:/Users/kaisios/Desktop/attempt9000.html<\\html>");

    VBox vBox = new VBox();
    vBox.getChildren().addAll(webView);

    Scene scene = new Scene(vBox, 800, 500);
    stage.setScene(scene);
    stage.show();
}

但它不加载内容。 注意:我已经运行了 xamp 服务器,但我认为 url 的公式是错误的

【问题讨论】:

    标签: javafx webview


    【解决方案1】:

    URL 有几个问题:

    • 协议:这可能是http。您需要在 url 的协议部分指定 IP
    • 环回IP是127.0.0.1而不是172.0.0.0
    • 端口在主机之后指定,在本例中为 IP
    • 端口可能不正确(在您的 xampp 控制面板中验证所使用的端口确实是 8080

    正确的网址(假设其余部分正确;请先使用您的标准网络浏览器检查)是

    http://127.0.0.1:8080/HOWEB/documentation
    

    如果您不想运行服务器,也可以使用文件 URL:

    File file = new File("C:/Users/kaisios/Desktop/attempt9000.html");
    engine.load(file.toURI().toString());
    

    收听onError 事件可以帮助您识别问题:

    engine.setOnError(evt -> {
        Throwable error = evt.getError();
        if (error != null) {
            error.printStackTrace();
        }
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-12-30
      • 2020-05-07
      • 2019-08-04
      • 2013-12-14
      • 1970-01-01
      • 2013-02-04
      • 1970-01-01
      相关资源
      最近更新 更多