Java:
html:
sql += " order by id desc,addtime desc";
System.out.println("sql="+sql);
String tmp = this.getExpenseService().getCount("Expense", sql);
if(tmp==null){
tmp = "0";
}
String first = request.getParameter("first");
String up = request.getParameter("up");
String down = request.getParameter("down");
String last = request.getParameter("last");
String page = request.getParameter("page");
// int count = Integer.valueOf(tmp);
int count=Integer.parseInt(tmp);
int max = 0;
int pagePer=10;
if (count % pagePer != 0) {
max = count / pagePer + 1;
} else {
max = count / pagePer;
}
if (request.getParameter("page") == null) {
page = "1";
}
int page2 = Integer.parseInt(page) - 1;
if (down != null) {
page2 += 1;
}
if (up != null) {
page2 -= 1;
}
if (first != null) {
page2 = 0;
}
if (last != null) {
page2 = max - 1;
}
if (page2 > max - 1) {
page2 = max - 1;
}
if (page2 < 0) {
page2 = 0;
}
if (count < pagePer) {
page2 = 0;
}
List list = this.getExpenseService().getListByHQL("Expense",page2*pagePer,pagePer,sql);
System.out.println("list.size="+list.size());
request.setAttribute("page", page2 + 1 + "");
request.setAttribute("totel", count + "");
request.setAttribute("list", list);
html:
<%
String pager = (String) request.getAttribute("page");
String totel = (String) request.getAttribute("totel");
String total = (String) request.getAttribute("total");
if (pager == null) {
pager = "1";
}
if (totel == null) {
totel = "0";
}
if (total == null) {
total = "0";
}
%>
<table width="80%" border="0" cellpadding="0" cellspacing="0" bordercolor="#4DB0E7" align="center">
<tr bgcolor="#FFFFFF">
<td width="17%">总记录 <font color='red' ><%=totel%></font> 条
<input class="button_y" name="first" type="submit" value="首页">
<input class="button_y" name="up" type="submit" value="上一页">
<input class="button_y" name="down" type="submit" value="下一页">
<input class="button_y" name="last" type="submit" value="末页">
</td>
<td width="17%">当前页为第
<input style="text-align: center" type="text" size="2" name="page" value=<%=pager%> readonly="readonly" />  页
</td>
</tr>
</table>