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

前端 未结 1 1993
半阙折子戏
半阙折子戏 2020-12-20 06:25

I have simple app with code:

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

Custom URLStreamHandler:

public class         


        
相关标签:
1条回答
  • 2020-12-20 07:17

    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");
    
    0 讨论(0)
提交回复
热议问题