我需要抛出404并将访问者带到特定页面。我正在尝试使用以下代码:
FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();
externalContext.setResponseStatus(HttpServletResponse.SC_NOT_FOUND);
externalContext.setResponseHeader(Common.LOCATION, "browse_by_category.xhtml?category=CATEGORY_ALL");
facesContext.responseComplete();
发生了404;但是没有发生重定向到browse_by_category.xhtml页面。
任何帮助将不胜感激。
答案 0 :(得分:3)
根据您的评论,请尝试:
FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();
externalContext.setResponseStatus(HttpServletResponse.SC_NOT_FOUND);
//externalContext.setResponseHeader(Common.LOCATION, "browse_by_category.xhtml?category=CATEGORY_ALL");
externalContext.dispatch("browse_by_category.xhtml");
facesContext.responseComplete();