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

问题描述 投票:1回答:1

我有一个简单的HTML页面error.html。我用的时候

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

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

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

jsf navigation
1个回答
6
投票

导航案例结果被视为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");
}
© www.soinside.com 2019 - 2024. All rights reserved.