JSTL标签库中没有<c:else 标签,使用<c:choose>替代,语法如下:
<c:choose>
<c:when test=""> 如果
</c:when>
<c:otherwise> 否则
</c:otherwise>
</c:choose>
例:
后台action:
List<Map> ver_list = new ArrayList<Map>();
String ver_item_a = req.getParameter("ver_item_a");
req.setAttribute("ver_item_a", ver_item_a);
req.setAttribute("ver_list", ver_list);
前台 jsp:
<c:forEach items="${ver_list}" var="row">
<c:choose >
<c:when test="${row.VER_ITEM ==ver_item_a}">
<option value="${row.VER_ITEM}" selected="selected">${row.VER_ITEM }</option>
</c:when>
<c:otherwise>
<option value="${row.VER_ITEM}" >${row.VER_ITEM }</option>
</c:otherwise>
</c:choose>
</c:forEach>