欢迎光临
我们一直在努力

一个分页BEAN-JSP教程,资料/其它

建站超值云服务器,限时71元/月

package xx;

import java.lang.*;

public class page {

private int totalpage,stride,currentpage;

//设置总页数

public void settotalpage(int objpage){

totalpage=objpage;

}

//设置当前页

public void setcurrentpage(int objpage){

currentpage=objpage;

}

//设置跨度

public void setstride(int objstride){

stride=objstride;

}

//获得总页数

public int gettotalpage(){

return totalpage;

}

//获得跨读

public int getstride(){

return stride;

}

//获取当前页

public int getcurrentpage(){

return currentpage;

}

//打印分页

public string show(){

string willprint=new string();

int p,tmpa;

for(tmpa=1;tmpa<=totalpage;tmpa++){

if(tmpa+stride<currentpage){//加了跨度还小于当前页的不显示

continue;

}

if(tmpa+stride==currentpage){//刚好够跨度的页数

p=currentpage-stride-1;

willprint+="<a href=\"?page=1\" title=\"首页\"><strong><font face=webdings>9</font></strong></a>&nbsp;<a href=\"?page="+p+"\" title=\"上页\"><strong><font face=webdings>7</font></strong></a>&nbsp;";

}

if(tmpa>currentpage+stride){//大于当前页+跨度的页面

break;

}

willprint+="<a href=\"?page="+tmpa+"\"><strong>"+tmpa+"</strong></a>&nbsp;";

if(tmpa==currentpage+stride){//刚好够跨度的页数

p=currentpage+stride+1;

willprint+="<a href=\"?page="+p+"\" title=\"下页\"><strong><font face=webdings>8</font></strong></a>&nbsp;<a href=\"?page="+totalpage+"\" title=\"尾页\"><strong><font face=webdings>:</font></strong></a>";

}

}

return willprint;

}

}

调用:

—–

<%@page import="java.util.*"%>

<%@page import="java.io.*"%>

<%@page contenttype="text/html;charset=gb2312"%>

<html>

<head>

<title>分页bean</title>

<meta http-equiv="content-type" content="text/html;charset=gb2312">

</head>

<style type="text/css">

body,td,input {font-size:12px;color:red}

</style>

<body>

<hr size="1" />

<jsp:usebean id="cm" class="xx.page" />

<%

string cpage=request.getparameter("page");

string stcpath=new string();

int dpage;

if(cpage==null){

cpage="1";

}

dpage=integer.parseint(cpage);

cm.settotalpage(100);

cm.setcurrentpage(dpage);

cm.setstride(5);

stcpath=cm.show();

out.println(stcpath);

%>

</body>

</html>

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 一个分页BEAN-JSP教程,资料/其它
分享到: 更多 (0)

相关推荐

  • 暂无文章