I have a String HTML content which is loaded into webEngine
by loadContent()
method. I have also some css and image files used in this page. Although I put these file into the same package of java class, the loaded page cannot find them. Looked for API docs and web, but could not find any appropiate similar solutions. How I load these files?
I just found out that using the <base>
tag in the HTML also does the trick:
<html>
<head>
<title>The slash at the end of the href is important!</title>
<base href="file:///absolute/path/to/your/docroot/" />
</head>
<body>
<img src="image.png"/>
</body>
</html>
If you load the above code via engine.loadContent(String)
then image.png
will be loaded from /absolute/path/to/your/docroot/image.png
.
This method is easier if you need to load multiple resources since you only have to specify the absolute path at a single place.
This has been tested with WebView
of Java 8u25.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With