我有一个纯 HTML 页面error.html。当我使用
return "error.html?faces-redirect=true";
它实际上会重定向到error.xhtml,而不是error.html。
如何在 JSF 操作方法中重定向到非 JSF 页面?
我有一个纯 HTML 页面error.html。当我使用
return "error.html?faces-redirect=true";
它实际上会重定向到error.xhtml,而不是error.html。
如何在 JSF 操作方法中重定向到非 JSF 页面?
导航案例结果被视为 JSF 视图。所以它总是需要一个 JSF 视图。如果由于某些不清楚的原因无法重命名error.html为error.xhtml(请记住,您可以在 Facelets 页面中安全地使用纯 HTML),那么您需要自己使用ExternalContext#redirect().
public void someAction() throws IOException {
// ...
ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
ec.redirect(ec.getRequestContextPath() + "/error.html");
}