我有index.jsp页面。
<form action="LoginServlet" method="post">
<fieldset style="width: 300px">
<legend> Login to App </legend>
<table>
<tr>
<td>User ID</td>
<td><input type="text" name="Emp_id" required="required" /></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="Pwd" required="required" /></td>
</tr>
<tr>
<td>User Type</td>
<td> <select name="usertype">
<option>Employee</option>
<option>Manager</option>
<option>Admin</option>
</select></td>
</tr>
<tr>
<td><input type="submit" value="Login" /></td>
</tr>
</table>
</fieldset>
</form>
header.jsp中: 当用户使用usertype作为“Employee”登录时,只有两个菜单选项必须显示在下一页的头文件中。如果usertype是“Admin”或“Manager”,那么它必须显示所有四个菜单选项。
<body>
<form name="headerform" action="Get">
<c:choose>
<c:when test="${usertype== Employee}">
<div class="nav">
<ul><li class="container"><img src="${pageContext.request.contextPath}/images/enabling.jpg" /></li>
<li class="current"><a href="daywise.jsp">DayWise TimeSheet</a></li>
<li><a href="timesheet.jsp">Weekly TimeSheet</a></li>
</ul>
</div>
</c:when>
<c:when test="${usertype== Manager}">
<div class="nav">
<ul><li class="container"><img src="${pageContext.request.contextPath}/images/enabling.jpg" /></li>
<li class="current"><a href="daywise.jsp">DayWise TimeSheet</a></li>
<li><a href="timesheet.jsp">Weekly TimeSheet</a></li>
<li><a href="newemployee.jsp">Add New Employeer</a></li>
<li><a href="retrieve.jsp">Retrieve TimeSheet</a></li>
</ul>
</div>
</c:when>
<c:when test="${usertype== Admin}">
<div class="nav">
<ul><li class="container"><img src="${pageContext.request.contextPath}/images/enabling.jpg" /></li>
<li class="current"><a href="daywise.jsp">DayWise TimeSheet</a></li>
<li><a href="timesheet.jsp">Weekly TimeSheet</a></li>
<li><a href="newemployee.jsp">Add New Employeer</a></li>
<li><a href="retrieve.jsp">Retrieve TimeSheet</a></li>
</ul>
</div>
</c:when>
<c:otherwise>
<div class="nav">
<ul><li class="container"><img src="${pageContext.request.contextPath}/images/enabling.jpg" /></li>
<li class="current"><a href="daywise.jsp">DayWise TimeSheet</a></li>
<li><a href="timesheet.jsp">Weekly TimeSheet</a></li>
</ul>
</div>
</c:otherwise>
</c:choose>
</form>
</body>
但是从上面的代码中只有员工选项可见......我是第一次使用jstl所以请告诉我该怎么做。或者是否有任何其他方法可以根据usertype隐藏选项。 Index.jsp与header.jsp不同。从index.jsp开始,usertype值必须转到其他jsp页面的header.jsp。
答案 0 :(得分:0)
您确定该员工是否可见?不是otherwise
选项吗?
您的情况有误,请尝试更改:
<c:when test="${usertype eq 'Employee'}">