I have defined a list collection in my servlet as following:
List<BookingRecord> list = getLast24();
req.setAttribute("records", list);
Then in JSP, I want to do following algorithm using jstl. If list is not empty, do XXXX, otherwise do YYYY.
I did something like this:
<c:when test="${not empty records}">
<table border="1">
<tbody>
<tr>
<th>id</th>
<th>hotel</th>
<th>room</th>
<th>guest id</th>
<th>start date</th>
<th>end date</th>
<th></th>
</tr>
<c:forEach items="${records}" var="record">
<tr<c:if test="${record.endDate != null }"> style="background-color: gainsboro"</c:if>>
<td>${record.id}</td>
<td>${record.hotelName}</td>
<td>${record.roomNumber}</td>
<td>${record.personId}</td>
<td><fmt:formatDate value="${record.startDate}" pattern="yyyy-MM-dd HH:mm"/></td>
<td><fmt:formatDate value="${record.endDate}" pattern="yyyy-MM-dd HH:mm"/></td>
<td>
<c:if test="${record.endDate == null }">
<form action="checkout" method="post">
<input type="hidden" name="recordId" value="${record.id}"/>
<input type="submit" value="退房"/>
</form>
</c:if>
</td>
</tr>
</c:forEach>
</tbody>
</table>
</c:when>
<c:otherwise>
<h1>目前24小时内,没有订房</h1>
</c:otherwise>
But the tomcat gave me exception at
<c:when test="${not empty records}">
I appreciate if someone could help me out.