我只是疑惑,當我使用<jsp:include file="include/data.jsp" />
在indexq.jsp我的數據並沒有顯示出來,但是當我使用它<%@ include file="include/data.jsp" %>
按預期工作。我不確定它是一個範圍還是表達式語言問題。我還包括下面的代碼:JSP/Servlet的範圍問題:包括標籤
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>
謝謝!
Thanks fmodos!現在對我來說很清楚,我只是在我的代碼中使用指令include。謝謝! – jzarsuelo
@ cRane01歡迎您,很高興提供幫助 – fmodos