[英]How to load new file in WebView?
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.
我有一个带web视图的阶段,我想有时更改HTML文件,但我无法重新加载Web视图并动态查看我的更改。
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. 这段代码有效,但仅适用于HTML文件的第一个版本,当我在HTML文件中更改某些内容并再次调用showme()时,没有任何反应。 The Html file is in a local directory.
Html文件位于本地目录中。 Is there any possibility to dynamically reload web-view?
是否有可能动态重新加载Web视图?
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
.JavaFX WebView的会话cookie存储在
java.net.CookieHandler
。To manage cookies on your own create new instance of
java.net.CookieManager:
要自己管理cookie,请创建
java.net.CookieManager:
新实例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:
要清除cookie,只需调用removeAll方法:
manager.getCookieStore().removeAll();
or just create new instance of cookie manager and set it as default:
或者只是创建cookie管理器的新实例并将其设置为默认值:
java.net.CookieHandler.setDefault(new java.net.CookieManager());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.