阅读次数:150发布日期:2019-06-04
jsp分页设计,通过传列表大小和当前页码来实现。在数据库方面用limit 参数进行查询
本次使用servlet和jsp、domain、dao、配合实现的
jsp页面代码如下:
<div class="page">
<%
String a= request.getAttribute("count").toString();
String aa=null;
if(request.getParameter("currentPage")!=null){
aa= request.getParameter("currentPage").toString();
}else{
aa="1";
}
int b= Integer.parseInt(a);
int bb=Integer.parseInt(aa);
int nextpage=bb+1;
int prepage=bb-1;
int c=b/5+2;
%>
<%
if(bb<2){
%>
<span style=" margin-right: 5px;">上一页 </span>
<%
}else{
%>
<a style=" margin-right: 5px;" href="YuangongServlet?action=list¤tPage=<%=prepage%>">上一页 </a>
<%
}
%>
<%
for(int i=1;i<c;i++){
%>
<a <%if(bb==i){%> style="color:#fff;background:red;" <% }%> href="YuangongServlet?action=list¤tPage=<%=i%>"><%=i%></a>
<%
}
%>
<%
if(bb>=c-1){
%>
<span>下一页 </span>
<%
}else{
%>
<a href="YuangongServlet?action=list¤tPage=<%=nextpage%>">下一页 </a>
<%
}
%>
总条数: <%=request.getAttribute("count")%>
</div>