如何比较当前用户的用户名和特定参数?

时间:2013-07-30 07:11:39

标签: java jsp spring-security

我需要找到用户的用户名,如果与特定用户名相同,我会向该用户显示一些额外信息。

使用以下代码,我可以检索当前用户的用户名,但不知道如何将其与特定的$ {username}进行比较。

 <sec:authentication property="name"/>

 <c:if test=" ? == ${username}">
   Hellow
 </c>

2 个答案:

答案 0 :(得分:2)

您可以声明一些变量并为其分配principal object:

<sec:authentication var="principal" property="principal" />

然后使用以下EL表达式获取用户名:

${principal.username}

所以你可以做点什么

<c:if test="${principal.username == username}">
   Hellow
</c>

答案 1 :(得分:1)

你可以尝试这样的事情:

<g:set var="user" value="${sec.username()}" />
<g:if test="${user == username}" >
    heelloo
</g:if>