A P*_*aul 5 java javafx javafx-webengine
使用JavaFx WebEngine,如何检测是否存在404页面未找到错误.我已搜索但无法找到任何内容.有任何想法吗?或者有可能吗?
最有可能的是,您必须添加自己的 URL 处理程序(如这篇文章javafx 2 webview 自定义 url 处理程序,不工作相对 url)并自己检索/检测 404 消息和条件。
本文(如何使用 Java 检查 URL 是否存在或返回 404?)向您展示如何检测 404 情况。
在处理程序中,您有 2 个选择,要么创建HEADURL 请求(然后忽略HEAD请求,这样您就不会陷入无限循环),要么在检查 404 后伪装返回的 URLConnection。
@Override
protected URLConnection openConnection(URL u) throws IOException {
// 1. Use Apache HTTPClient or something else to grab the url
// 2. Read the resultCode and report if it's a 404
// 3. Return an object that subclasses URLConnection
}
Run Code Online (Sandbox Code Playgroud)