Servlet代碼:
List<FoodType> foodList = service.findAll(); request.setAttribute("foodList", foodList); // 2. 跳轉(zhuǎn) uri = "/sys/type/foodtype_list.jsp"; request.getRequestDispatcher(uri).forward(request, response);
以下是jsp的顯示代碼:
<c:choose> <c:when test="${not empty requestScope.foodList} "> <c:forEach items="${requestScope.foodList }" var="foodType" varStatus="vs"> <tr> <td>${vs.count }</td> <td>${foodType.foodTypeName }</td> <td><a href="${pageContext.request.contextPath }/FoodTypeServlet?method=editview&id=${foodType.id}" class="FunctionButton">更新</a> <a href="${pageContext.request.contextPath }/FoodTypeServlet?method=delete&id=${foodType.id}" class="FunctionButton">刪除</a></td> </tr> </c:forEach></c:when> <c:otherwise> <td colspan="3">暫未添加任何菜系!</td> </c:otherwise> </c:choose>
Servlet傳過來的foodList是有值的,如果直接用 forEach 是可以顯示的 為什么加了 test 判定就不行了呢? 困擾了很久 網(wǎng)上也沒有找到答案 希望有大神可以解答!