我有一个简单的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()
自行向非JSF资源发送重定向。
public void someAction() throws IOException {
// ...
ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
ec.redirect(ec.getRequestContextPath() + "/error.html");
}