0

我需要一个分页链接,如Prev 1-10 Next,Prev 11-20 Next等。我有一个数组列表,比如 arList ,其中包含 300 条记录。我需要先显示前 10 条记录。仅单击下一步时,我需要显示下一个 10。

任何人都可以分享一个链接或资源有类似的想法吗?

ArrayList arList  = new ArrayList();
arList = // calling method to retrieve elements

// table starts here
<table id="tbl">


 for(int i=0; i < arList.size();i++) 
 {
 HashMap hMap=(HashMap)arList.get(i);                        
 firstVal= (String)hMap.get("first");
 secondVal= (String)hMap.get("second");
%><tr><td> 
// firstVal and secondVal goes here
</tr></td><%
 }

</table>
4

1 回答 1

1

你可以为此使用JSTL!

<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
...
<c:forEach items="${list}" var="item" begin="0" end="9">
    ${item}
</c:forEach>

您甚至可以在这些属性中使用 EL。

request.setAttribute("firstrow", 0);
request.setAttribute("rowcount", 10)

<c:forEach items="${list}" var="item" begin="${firstrow}" end="${firstrow + rowcount - 1}">
    ${item}
</c:forEach>
于 2013-03-27T05:59:42.823 回答