我在jsp中执行分页,但我的jstl不打印结果
<%
RecordDao dao = new RecordDao();
int pg = 1;
int recordsPerPage = 5;
if(request.getParameter("pg") != null) {
pg = Integer.parseInt(request.getParameter("pg"));
}
List<RecordBean> recordList = dao.getAllRecords((pg-1)*recordsPerPage, recordsPerPage);
int noOfRecords = dao.getNoOfRecords();
int noOfPages = (int) Math.ceil(noOfRecords * 1.0 / recordsPerPage);
request.setAttribute("recordList", recordList);
request.setAttribute("noOfPages", noOfPages);
request.setAttribute("currentPage", pg);
%>
<table>
<c:forEach var="record" items="${recordList}">
<tr>
<td>${record.data1}</td>
<td>${record.data2}</td>
<td>${record.data3}</td>
<td>${record.data4}</td>
<td>${record.data5}</td>
</tr>
</c:forEach>
</table>
<c:if test="${currentPage != 1}">
<a href="DemoList.jsp?pg=${currentPage - 1}">Previous</a>
</c:if>
<c:if test="${currentPage lt noOfPages}">
<a href="DemoList.jsp?pg=${currentPage + 1}">Next</a>
</c:if>
当我检查chrome内的元素时,我得到以下结果。
<c:foreach var="record" items="[com.java.bean.RecordBean@149a5a3, com.java.bean.RecordBean@19a655, com.java.bean.RecordBean@1f748c4, com.java.bean.RecordBean@1ca3cde, com.java.bean.RecordBean@621bf1">
</c:foreach>
答案 0 :(得分:-2)
你可以这样做(例子):
<select>
<% for(RecordBean r : recordList){ %>
<option> <% r %> </option>
<%}%>
</select>