0

I want to display local .html with .css and .js by WebView. Here is my code:

    WebView webView = new WebView();
    WebEngine webEngine = webView.getEngine();
    webEngine.load(Main.class.getResource("/dashboard/index.html").toExternalForm());
    Stage webViewStage = new Stage();
    webViewStage.setScene(new Scene(new StackPane(webView)));
    webViewStage.show();

And that folder structure where .html located:

enter image description here

But my local web page loaded like this:

enter image description here

instead of this:

enter image description here

why?

teXI
  • 51
  • 9
  • https://stackoverflow.com/a/34339752/2740650 might help – user2740650 Feb 27 '21 at 14:41
  • @user2740650 thanks, but in index.html are to many links to .css and .js files, that by itself contains a lot of links (i.e. bootstrap). By the way web pages from the web loaded normally. – teXI Feb 27 '21 at 14:54
  • Hmm, what does `Main.class.getResource("/dashboard/index.html").toExternalForm()` look like? If it's not `file://something` then that might explain why it doesn't work for local URLs. – user2740650 Feb 27 '21 at 15:20
  • @user2740650 file:/Users/anahel/Documents/Projects/IdeaProjects/sql-load-test-without-maven/out/production/sql-load-test-without-maven/dashboard/index.html – teXI Feb 27 '21 at 15:46
  • That doesn't look quite right. I'd expect "file:///". https://stackoverflow.com/questions/35703884/trying-to-load-a-local-page-into-javafx-webengine has a comment "note no leading / on the path" so you could try that. Also, verify that you can open the url in your own browser (Chrome or whatever), and try pasting that full URL in as a test case. – user2740650 Feb 27 '21 at 16:28
  • @user2740650 my app shows page without .css and .js both with "file:///" and "file:/". My browser shows page correct both with "file:///" and "file:/". – teXI Feb 27 '21 at 16:51
  • It might be important that I build project without maven – teXI Feb 27 '21 at 19:36

0 Answers0