I have a jsp page which contains the same menu bar for everyone, each user has a permission depending on his status ( if he is an administrator or user ..) i want to disable some item menu bar if the user logged in is an administrator , and enable the other ones How can i achieve this, please suggest. Thanks in advance
Asked
Active
Viewed 1,391 times
1 Answers
1
Set the role in session and get it in JSP page. In servlet,
session.setAttribute("Role", "administrator");
And in JSP,
<%
String role= (String)session.getAttribute("Role");
pageContext.setAttribute("role",role);
%>
Here I assumed that you are using JSTL for standard (Just add this line <%@ taglib prefix="c"
uri="http://java.sun.com/jsp/jstl/core" %>
).
<c:choose>
<c:when test="{role == 'administrator'}">
<!-- Menu Choice 1 -->
</c:when>
<c:otherwise>
<!-- Menu Choice 2 -->
</c:otherwise>
</c:choose>
See BalusC answer for more details. Hope this helps.

Community
- 1
- 1

Vinoth Krishnan
- 2,925
- 6
- 29
- 34
-
thanks for your help , but the result is always the second menu whatever is the user logged in . if we suppose that the first menu choice is for the administrator , and the user logged in is an administrator , i want to have the first menu choice enabled and the second one shown but it s disabled – mimo Mar 01 '16 at 12:36
-
Can you post your relevant JSP and servlet code by edit your question? – Vinoth Krishnan Mar 01 '16 at 12:41
-
i couldn't post the code , it s too long and i had a problem with the format of the message , thank you any way for your help – mimo Mar 01 '16 at 20:25