在用<c:if>时,记得导入c标签<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<c:if>标签判断表达式的值,如果表达式的值为 true 则执行其主体内容。
<c:if test="<boolean>" var="<string>" scope="<string>">
...
</c:if>
属性 | 描述 | 是否必要 | 默认值 |
test | 条件 | 是 | 无 |
var | 用于存储条件结果的变量 | 否 | 无 |
scope | var属性的作用域 | 否 | page |
<c:set var="type" scope="session" value="<%=type%>"/>
<c:if test="${type.equals('1')}">
<td class="grid_title" height="30px">原材料名称 <font color="red">*</font></td>
</c:if>
<c:if test="${type.equals('2')}">
<td class="grid_title" height="30px">半成品名称 <font color="red">*</font></td>
</c:if>
<c:if test="${type.equals('3')}">
<td class="grid_title" height="30px">成品名称 <font color="red">*</font></td>
</c:if>
如上所示,只要 ${type.equals('1')} 为true即可执行<td>语句
拓展:
<!-- 判断结束时间是否为空 如果需要判断非空 则 使用 not empty 字段 即可 -->
<c:if test="${empty task.endTime}">
<a href="#">办理</a>
</c:if>
判断List是否为空
<c:if test="${not empty recordList}">
...
</c:if>