How to check if is user logged in?

前端 未结 3 1869
不思量自难忘°
不思量自难忘° 2020-12-05 16:56

I want do display a login link when the user isn\'t logged in and a logout link when the user is logged in. I\'m using container managed security as defined in web.xml

3条回答
  •  孤城傲影
    2020-12-05 17:36

    The username of the logged-in user is available by ExternalContext#getRemoteUser() which delegates under the covers to HttpServletRequest#getRemoteUser(). Both are available in EL by #{facesContext.externalContext.remoteUser} and #{request.remoteUser} respectively. If it is null, then it means that the user is not logged in.

    So, in your view you can check it in the rendered attribute as follows:

    
        
    
    
    

    See also:

    • Conditionally displaying JSF components

提交回复
热议问题