问题
i need pagination concept to display 15 records. this is my jsp file.
<%
ArrayList<String> al = new ArrayList();
%>
<%!String s;
int i;%>
<%
al = op.getCountry();
%>
<jsp:scriptlet>
session.setAttribute( "EmpList", al);
</jsp:scriptlet>
<display:table id="domList" pagesize="10" name="sessionScope.EmpList">
<table width="100%" border="0" cellpadding="0" cellspacing="0" id="dataTable">
<tr bgcolor="#57e3ff">
<td><strong>Country</strong></td>
<td colspan="2" align="center"><strong>Action</strong></td>
</tr>
<% int a = 0, i = 0;
while (i < al.size()) {
if ((i + 1) % 2 == 0) {
s = "#f3f4f4";
} else {
s = "#ebebec";
}%>
<tr bgcolor="<%=s%>">
<td><display:column value="<%=al.get(i)%>" /> </td>
<td align="center"><div id='basic-modal-cdel'>
<a href='#' id="<%=al.get(i)%>" onclick="return del();"
class='basic-cdel'><img src="${pageContext.request.contextPath}/images/delete.png"
alt="Delete" title="Delete" border="0" /></a>
</div></td>
<td align="center"><div id='basic-modal-country'>
<a href='#' id="<%=al.get(i)%>" class='basic-country'
onclick="validatedit()"><img src="${pageContext.request.contextPath}/images/edit-icon.png"
alt="Update" title="Update" border="0" /></a>
</div></td>
</tr>
<%
i++;
a++;
}
%>
please help me iam newbie in pagination. i want to show only 10 records per page. i tried it through display tag but i cant figure it out.
回答1:
The Display Tag library is an open source library which provides pagination functionality while still being easy to use.
You can set your records in request scope from your servlet class.
request.setAttribute( "test", new TestList(10, false) );
and Then you can use display tag library to display it with pagination.
<%@taglib uri="http://displaytag.sf.net" prefix="display" %>
<display:table name="test" pagesize="15" >
<display:column property="id" title="ID" />
<display:column property="name" />
<display:column property="email" />
<display:column property="status" />
<display:column property="description" title="Comments"/>
</display:table>
You can find it's basic tutorials here.
Updated:
You need not to use <table>, <tr>, <td>
tag only <display:table> and <display:column>
is enough.
You can directly use fields from EmpList inside property tag of <display:column>
.
Follow this tutorial.
回答2:
You can you the Display tag library. It provides paging capability for your JSP page. You just need to pass a list of objects to this taglib and it will add pagination to your page. It also support other functionality such as sorting, grouping, export, etc.
回答3:
I am using Display Tag Library
and it does everything by fly. Just pass the list into the display:table property and display tag will take care of the rest. You can also use EL with it. It is easy to use and also maintainable.
来源:https://stackoverflow.com/questions/17939431/how-to-perform-pagination-in-jsp