1

I have a problem with my program. I have a stage with web-view and I want to change HTML file sometimes, but I can't reload web-view and see my changes dynamically.

public void showme(String what) {
    try {
        WebEngine webEngine = webvw.getEngine();
        System.out.print("vsengine_projects/" + xoxo + "/" + what);
        URL url = this.getClass().getResource("vsengine_projects/" + xoxo + "/"  + what);
        webEngine.load(url.toString());
        System.out.println("KK");
    } catch (Exception e) {
        System.err.println("EXC " + e);
    }
}

This code works, but just for the first version of the HTML file, when I change something in the HTML file and call showme() again, nothing happen. The Html file is in a local directory. Is there any possibility to dynamically reload web-view?

1 Answers1

0

I think you will need to clear the cache before displaying it. Maybe call the following at the start of the function:

java.net.CookieHandler.setDefault(new java.net.CookieManager());

I found how to clear session data from this answer quoted below:

Session cookies for JavaFX WebView are stored in java.net.CookieHandler.

To manage cookies on your own create new instance of java.net.CookieManager:

java.net.CookieManager manager = new java.net.CookieManager();

Then set it as default:

java.net.CookieHandler.setDefault(manager);

To clear cookies just call removeAll method:

manager.getCookieStore().removeAll();

or just create new instance of cookie manager and set it as default:

java.net.CookieHandler.setDefault(new java.net.CookieManager());
Community
  • 1
  • 1
Tony
  • 2,890
  • 1
  • 24
  • 35