2017-05-25 36 views
0

我有一個多用戶門戶,我爲兩個用戶(管理員和教師)在securedHolder中存儲值。但不存儲超級管理員的值。在JSP中檢查特定值是否設置

我必須根據用戶角色(管理員,教師和超級管理員)顯示導航菜單。

所以我想檢查一下JSP頁面中的值是否設置。如何在JSP中做到這一點?

我檢查了用戶角色,但無法檢查特定值。

<sec:authorize access="hasRole('ROLE_TEACHER')"> 
     -- Do something for teacher 
     -- want to check the value here 
</sec:authorize> 

回答

0

每當用戶登錄時,爲什麼不在用戶會話中將角色屬性保存爲「teacher」,「admin」或「superadmin」?

然後,你可以做這樣的事情使用JSTL標籤:

<c:choose> 
    <c:when test="${sessionScope.user.role == 'teacher'}"> 
     your nav bar for teachers 
    </c:when> 
    <c:when test="${sessionScope.user.role == 'admin'}"> 
     your nav bar for admins 
    </c:when> 
    <c:when test="${sessionScope.user.role == 'superadmin'}"> 
     your nav bar for superadmins 
    </c:when> 
    <c:otherwise> 
     your nav bar for somebody else 
    </c:otherwise> 
</c:choose> 
+0

然後,您可以將任何區分超級管理員的任何內容添加爲您的控制器中的模型屬性。並檢查使用''標記。 – viz

+0

這個角色已經在由'spring-security'管理的'Authentication'對象的會話中。沒有必要爲響應做這個thanx – jlumietu

+0

,但是我通過使用 ankit

0

不要使用它jstl這樣:

<c:if test="${not empty var}"> 
    <div>do whatever you need</div> 
</c:if> 

混合所有,我會做這樣的:

<sec:authorize access="hasAnyRole('ROLE_TEACHER','ROLE_ADMIN')"> 
    <c:if test="${not empty var}"> 
     <div>do whatever you need</div> 
    </c:if> 
</sec:authorize> 
+0

thanx來完成響應。我通過使用 ankit

0

通過使用完成 <sec:authorize access="principal.securedHolder['value']==requiredvalue"></sec:authorize>

相關問題