How to throw 404 from bean in jsf

前端 未结 1 1505
花落未央
花落未央 2021-01-20 20:32

I need to throw 404 and take visitor to a specific page. I am trying with following code:

            FacesContext facesContext = FacesContext.getCurrentInst         


        
相关标签:
1条回答
  • 2021-01-20 21:11

    According to your comment please try this:

    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();
    
    0 讨论(0)
提交回复
热议问题