如何在jsf中从bean中抛出404

时间:2014-10-29 15:32:18

标签: jsf-2 http-response-codes

我需要抛出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页面。 任何帮助将不胜感激。

1 个答案:

答案 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();