开发者

check property value in struts2

开发者 https://www.devze.com 2023-04-01 00:59 出处:网络
I have currently login User object (userId,organisationId,etc.. ) stored in session by using like this.

I have currently login User object (userId,organisationId,etc.. ) stored in session by using like this.

session.setAttribute("user", LoginUser);

Where my LoginUser is User object with detail information.

In my next jsp page, I want to check the user's organisationId by calling from Session.

<s:property value="%{#session.user.organisationId}"/>

How can I check the organisationId in property value is 0 or etc., and do things according to va开发者_运维技巧rious IDs?

How can I check using c:choose?

Thanks.


<c:choose>
  <c:when test="${user.organizationId == 1}">
        <!-- do something -->
  </c:when>
  <c:otherwise>
        <!-- do something different -->
  </c:otherwise>
</c:choose>


Using JSTL, either <c:if> conditional tag:

<c:if test="${sessionScope.user.organisationId == 0}">

</c:if>

Or using <c:choose> conditional tag:

<c:choose>
    <c:when test="${sessionScope.user.organisationId == 0}">
        <!-- true -->
    </c:when>
    <c:otherwise>
        <!-- false -->
    </c:otherwise>
</c:choose>


<s:if test="#session.user.organisationId == 0">
 <p>I'm Zero.</p>
</s:if>
<s:elseif test="#session.user.organisationId == 1">
 <p>I am One.</p>
</s:elseif>
<s:else>
    <p>I not either of these things.</p>
</s:else>

organisationId must be a numeric type.

0

精彩评论

暂无评论...
验证码 换一张
取 消