1、如果html文件在jar包内,就是在classpath就这样加载
webView.getEngine().load(WebViewStyle.class.getResource("/com/html/ScriptToJava.html").toExternalForm());
2、如果html文件在项目之外
File file = new File("Resources/Html/Chat/show/show.html");
String absolutePath = file.getAbsolutePath();
absolutePath = absolutePath.replace("\\", "/");
if (absolutePath.startsWith("/")) {
webView.getEngine().load("file:" + absolutePath);
}else {
webView.getEngine().load("file:/" + absolutePath);
}
3、js调用Java对象
(1)、Java class需要是public
(2)提交实例化java对象和页面加载完再设置
(3)调用
是javafx 不是安卓