javafx 2 webview custom url handler, don't work relative url

喜欢而已 提交于 2019-11-29 12:53:20

I thin I found the solution:

in Handler.openConnection(URL u) we have to add

String path = getURL().getPath().startsWith("/") ? getURL().getPath().substring(1) : getURL().getPath();
URL resourceUrl = classLoader.getResource(path);

instead of

URL resourceUrl = classLoader.getResource(u.getPath());

and to standartize URL, instead

webView.getEngine().load("classpath:data/index.html");

use

webView.getEngine().load("classpath:///data/index.html");
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!