jsp和jstl技术实现分页
2013-09-11
展开全部
request.setCharacterEncoding("GBK");
int p=1;
if(request.getParameter("page")!=null)
p = Integer.parseInt(request.getParameter("page"));
Operator operator =new Operator();
List<BookInfo> list= operator.getBookList(p,5);
int Allpages=operator.getAllPages(5);
int upPage=p; //上一页
int downPage=p; //下一页
if(p!=1){
upPage-=1;
}
if(p!=Allpages){
downPage+=1;
}
<tr>
<td align="right"><a href="infoList.jsp?page=<%=upPage %>">上一页</a>
<%
int begin =1; //起始页
int end=Allpages; //结束页
if(Allpages<=5){
begin=1;
end=Allpages;
}else{
if(Allpages-p>=5){
begin=p;
end=p+4;
}else{
begin=Allpages-4;
end=Allpages;
}
}
for(int i=begin;i<=end;i++){
if(i==p){
out.print("【"+i+"】");
}else{
%>
<a href="infoList.jsp?page=<%=i %>">【<%=i %>】</a>
<%
}
} %>
<a href="infoList.jsp?page=<%=downPage %>">下一页</a></td>
</tr>
int p=1;
if(request.getParameter("page")!=null)
p = Integer.parseInt(request.getParameter("page"));
Operator operator =new Operator();
List<BookInfo> list= operator.getBookList(p,5);
int Allpages=operator.getAllPages(5);
int upPage=p; //上一页
int downPage=p; //下一页
if(p!=1){
upPage-=1;
}
if(p!=Allpages){
downPage+=1;
}
<tr>
<td align="right"><a href="infoList.jsp?page=<%=upPage %>">上一页</a>
<%
int begin =1; //起始页
int end=Allpages; //结束页
if(Allpages<=5){
begin=1;
end=Allpages;
}else{
if(Allpages-p>=5){
begin=p;
end=p+4;
}else{
begin=Allpages-4;
end=Allpages;
}
}
for(int i=begin;i<=end;i++){
if(i==p){
out.print("【"+i+"】");
}else{
%>
<a href="infoList.jsp?page=<%=i %>">【<%=i %>】</a>
<%
}
} %>
<a href="infoList.jsp?page=<%=downPage %>">下一页</a></td>
</tr>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询