我只是感到困惑,当我<jsp:include file="include/data.jsp" />
在indexq.jsp中使用时,我的数据没有显示出来,但是当我使用<%@ include file="include/data.jsp" %>
它时,它可以按预期工作。我不确定它是范围还是表达式语言问题。我还包括以下代码:
TaxiController.java
public class TaxiController extends HttpServlet {
// codes...
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
// codes...
req.setAttribute("taxi_list", taxiDao.getAll());
req.getRequestDispatcher("/indexq.jsp").forward(req, resp);
}
}
indexq.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<script src="js/jquery-1.10.1.min.js" ></script>
<title>Taxi List</title>
</head>
<body>
<%@ include file="include/form.jsp" %>
<br />
<jsp:include page="include/data.jsp" />
<%-- <%@ include file="include/data.jsp" %> --%>
</body>
</html>
包含/data.jsp
<table>
<thead>
<tr><th colspan="5">Data</th></tr>
<tr>
<th>Date</th>
<th>Taxi Name</th>
<th>Plate number</th>
<th>Amount</th>
</tr>
</thead>
<tbody>
<c:forEach var="taxi" items="${taxi_list }" >
<tr>
<td>${taxi.date } </td>
<td>${taxi.taxiName }</td>
<td>${taxi.plateNum }</td>
<td>${taxi.amount }</td>
</tr>
</c:forEach>
</tbody>
</table>
谢谢!