1

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

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

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

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

4

1 回答 1

6

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

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

    ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
    ec.redirect(ec.getRequestContextPath() + "/error.html");
}
于 2013-01-25T12:17:38.663 回答