在jsp页面中使用<c:if标签比较两个值

来源:互联网 发布:sql 恢复挂起 编辑:程序博客网 时间:2024/05/01 08:19
<c:if标签作用是比较两个变量的值是否相等,要想使用c标签首先应该导入c标签库。
 <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

          

下面讲一个案例,如何比较一个el表达式获取到的值和一个使用java代码获取到的值。

          1.如:${subject['employee_id']}为文章发表者id;

          2.如:Session.getSession("userinfo").get("name"));当前登录人id

 

如何比较呢 

可以先把java代码代表的变量存入pageContext中,然后通过el表达式来取        

<%pageContext.setAttribute("username", Session.getSession("userinfo").get("name")); %>
       

然后

<c:if test="${subject['employee_id'] eq username}"><span style="cursor: pointer;font-weight:bold;"><a title="删除" style="color:red;" onclick="del('$[id]')">X</a></span></c:if>

        

0 0
原创粉丝点击