首先声明:el无法嵌套使用!
开发过程中遇到了需要el嵌套使用的情况,具体情况为
<c:forEach begin="0" end="3" step="1" var="i">
<td style="width:19%">
<c:if test="${id<indexList.size}">
<img src="${pageContext.request.contextPath }/videoFile/${indexList.get(${i}).v_id}/${indexList.get(${i}).v_id}.png" alt="${indexList.get(id).v_title} " />
<div>${indexList.get(${i}).v_title} </div>
</c:if>
</td>
</c:forEach>
我试图使用foreach中的数据作为el表达式的查询条件,上面写法是错误的,实际应当将想要嵌套的数据使用c:set标签存入域中再进行嵌套,另外上面代码中获取list的size的方法也是错误的,正确方法应当使用function标签,正确代码如下
<c:forEach begin="0" end="3" step="1" var="i">
<c:set value="${i}" var="id"> </c:set>
<c:set value="${fn:length(indexList)}" var="size"></c:set>
<td style="width:19%">
<c:if test="${id<size}">
<img src="${pageContext.request.contextPath }/videoFile/${indexList.get(id).v_id}/${indexList.get(id).v_id}.png" alt="${indexList.get(id).v_title} " />
<div>${indexList.get(id).v_title} </div>
</c:if>
</td>
</c:forEach>