我想设置两个变量使用2如果条件,但它不工作。 我下面的代码片段给出:如果条件不工作在JSTL
<c:forEach items="${user.roles}" var="role">
<span>Value : ${role.id }</span> **<!-- Print the value perfectly-->**
<c:if test="${role.id == 3}">
<c:set var="admin" value="${role.id}"></c:set>
<span>Value : ${val }</span>
</c:if>
<c:if test="${role.id == 2}"> **<!-- But not work condition here -->**
<c:set var="supporter" value="${role.id}"></c:set>
<span>Value : ${val }</span>
</c:if>
</c:forEach>
<input type="checkbox" name="roles" value="3" ${admin ==3 ? 'checked' : ''}> Supporter
<input type="checkbox" name="roles" value="2" ${supporter ==2 ? 'checked' : ''}> Admin
添加标签库:
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
你不应该使用'$'内'{}' ..replace'$ {$ role.id ==}'with'$ {role.id ==}' –