How to redirect to another page when already authenticated user accesses login page

后端 未结 2 1974
情歌与酒
情歌与酒 2020-12-19 10:31

I was wondering if it was possible to redirect users if a certain c:if clausule is true?



        
2条回答
  •  情歌与酒
    2020-12-19 10:48

    Apart from the Filter approach, you can also use . Put this somewhere in top of the view:

    
    

    And add this listener method to the LoginController:

    public void checkAuthentication() throws IOException {
        ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
    
        if (externalContext.getUserPrincipal() != null) {
            externalContext.redirect(externalContext.getRequestContextPath() + "/index.xhtml");
        }
    }
    

    That's all.

    See also:

    • Is there any easy way to preprocess and redirect GET requests?

提交回复
热议问题