【问题标题】:How can I redirect to a plain HTML page in JSF action method?如何在 JSF 操作方法中重定向到纯 HTML 页面?
【发布时间】:2013-01-25 03:41:46
【问题描述】:

我有一个纯 HTML 页面 error.html。当我使用

return "error.html?faces-redirect=true";

它实际上会重定向到error.xhtml,而不是error.html

如何在 JSF 操作方法中重定向到非 JSF 页面?

【问题讨论】:

标签: jsf navigation


【解决方案1】:

导航案例结果被视为 JSF 视图。所以它总是需要一个 JSF 视图。如果由于某些不清楚的原因无法将 error.html 重命名为 error.xhtml(请记住,您可以在 Facelets 页面中安全地使用纯 HTML),那么您需要自己发送重定向到非 JSF 资源 使用ExternalContext#redirect()

public void someAction() throws IOException {
    // ...

    ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
    ec.redirect(ec.getRequestContextPath() + "/error.html");
}

【讨论】:

    猜你喜欢
    • 2013-10-29
    • 1970-01-01
    • 2015-02-14
    • 1970-01-01
    • 2020-04-20
    • 2016-06-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多