我想設置兩個變量使用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 ==}' –