jsf check user logged in

ε祈祈猫儿з 提交于 2019-12-07 19:23:25

问题


How can I check if a user is logged in using jsf?

This is how I am doing it and it's not working:

<ui:fragment rendered="#{!request.getUserPrincipal().getName().equalsIgnoreCase('anonymous')}">
    <h:outputLink value="logout">
        <h:outputText value="Logout" />
    </h:outputLink>
</ui:fragment>

回答1:


Just check if HttpServletRequest#getUserPrincipal() is not null.

<ui:fragment rendered="#{request.userPrincipal != null}">
    <h:outputLink value="logout">
        <h:outputText value="Logout" />
    </h:outputLink>
</ui:fragment>

It also works for HttpServletRequest#getRemoteUser().

<ui:fragment rendered="#{request.remoteUser != null}">
    <h:outputLink value="logout">
        <h:outputText value="Logout" />
    </h:outputLink>
</ui:fragment>


来源:https://stackoverflow.com/questions/7704027/jsf-check-user-logged-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!