求jsp分页代码,最好是用标签的
这个分页代码能够起到复用,那是最好的。希望那位高手帮忙。本人分少,所以就很吝啬,望谅解。谢谢了。...
这个分页代码能够起到复用,那是最好的。希望那位高手帮忙。本人分少,所以就很吝啬,望谅解。谢谢了。
展开
3个回答
展开全部
<%@ page contentType="text/html; charset=gb2312"%>
<%@ page import="java.util.Date,java.sql.*"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<body>
<%
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn=DriverManager.getConnection("jdbc:odbc:student1");
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
ResultSet rs=null;
int p,m,n;
int PageSize=5;//页显示记录数
int RowCount=0;//总的记录数
int PageCount=0;//总页数
int ShowPage=1;//待显页码
String sql=null;
String search_txt="";
String ToPage=request.getParameter("ToPage");
if (request.getParameter("search_txt")!=null && !(request.getParameter("search_txt").equals("")))
{
search_txt=new String(request.getParameter("search_txt").trim().getBytes("8859_1"));
}
if (search_txt!=null && !(search_txt.equals("")))
{
sql="select * from xsqk where xuhao like'%"+search_txt+"%'";
sql=sql+"or xuehao like'%"+search_txt+"%'";
sql=sql+"or xingming like'%"+search_txt+"%'";
sql=sql+"or xingbie like'%"+search_txt+"%'";
sql=sql+"or xibie like'%"+search_txt+"%'";
sql=sql+"or banji like'%"+search_txt+"%'";
sql=sql+"or mingzhu like'%"+search_txt+"%'";
sql=sql+"or jiating like'%"+search_txt+"%'";
sql=sql+"or shengfeng like'%"+search_txt+"%'";
sql=sql+"or lianxi like'%"+search_txt+"%'";
sql=sql+"order by ID";
}
else
{
sql="select * from xsqk order by xuehao";
}
rs=stmt.executeQuery(sql);
rs.last();
RowCount=rs.getRow();
PageCount=((RowCount % PageSize)==0?(RowCount/PageSize):(RowCount/PageSize)+1);
if(ToPage!=null)
{
ShowPage=Integer.parseInt(ToPage);
if(ShowPage>PageCount)
{
ShowPage=PageCount;
}
else if(ShowPage<=0)
{
ShowPage=1;
}
}
rs.absolute((ShowPage-1)*PageSize+1);
%>
<font size="6">学生成绩表</font>
<%
if (search_txt!=null && !search_txt.equals(""))
{
%>
以下是包含关键字<font size="6" color="#FF0000"><%=search_txt%></font>的所有信息
<%
}
else
{
%>
以下所有信息
<%
}
%>
共<font color="#FF0000"><%=RowCount %></font>条
共<font color="#FF0000"><%=PageCount%></font>页
当前页为第<font color="#FF0000"><%=ShowPage%></font>页
<%
if(PageCount>1)
{
if(ShowPage-3>0)
{
m=ShowPage-3;
}
else
{
m=1;
}
if(ShowPage+3>PageCount)
{
n=ShowPage+3;
}
else
{
n=PageCount;
}
%>
转到页码:[
<%
for(p=m;p<=n;p++)
{
if(ShowPage==p)
{
%>
<font color="#0000FF"><b><%=p%></b></font>
<%
}
else
{
%>
<a
<%
if(ShowPage==p)
{
%>
style="color:red"
<%
}
%>
href="fenye.jsp?ToPage=<%=p%>&search_txt<%=search_txt%>"><%=p%></a>
<%
}
}
%>
]
<%
}
%>
<table align=center border=1 width=900>
<tr align=center>
<td>序号</td>
<td>学号</td>
<td>姓名</td>
<td>性别</td>
<td>系别</td>
<td>班级</td>
<td>民族</td>
<td>家庭住址</td>
<td>身份证号</td>
<td>联系电话</td>
</tr>
<%
for(int i=1;i<PageSize;i++)
{
out.println("<tr align=center>");
out.println("<td>"+rs.getString("xuhao")+"</td>");
out.println("<td>"+rs.getString("xuehao")+"</td>");
out.println("<td>"+rs.getString("xingming")+"</td>");
out.println("<td>"+rs.getString("xingbie")+"</td>");
out.println("<td>"+rs.getString("xibie")+"</td>");
out.println("<td>"+rs.getString("banji")+"</td>");
out.println("<td>"+rs.getString("mingzhu")+"</td>");
out.println("<td>"+rs.getString("jiating")+"</td>");
out.println("<td>"+rs.getString("shengfeng")+"</td>");
out.println("<td>"+rs.getString("lianxi")+"</td>");
out.println("</tr>");
if(!rs.next()) break;
}
%>
</table>
<table border="0" width="900">
<tr valign="baseline" align="center">
<td width="500"> </td>
<%
if(ShowPage!=1)
{
%>
<td width="50"><a href="fenye.jsp?ToPage=<%=1 %>&search_txt<%=search_txt%>">第一页 </a></td>
<td><a href="fenye.jsp?ToPage=<%=ShowPage-1 %>&search_txt<%=search_txt%>">上一页</a></td>
<%
}
if(ShowPage!=PageCount)
{
%>
<td width="50"><a href="fenye.jsp?ToPage=<%=ShowPage+1 %>&search_txt<%=search_txt%>">下一页</a></td>
<td><a href="fenye.jsp?ToPage=<%=PageCount %>&search_txt<%=search_txt%>">最后页</a></td>
<%
}
%>
<form action="fenye.jsp" method="post">
信息关键字搜索:
<input type="text" name="search_txt" size="17" value="<%=search_txt%>">
<input type="submit" value="搜索" name="B1">
</form>
<%
rs.close();
stmt.close();
conn.close();
}
catch(Exception e)
{
out.println(e.toString());
}
%>
</body>
</html>
<%@ page import="java.util.Date,java.sql.*"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<body>
<%
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn=DriverManager.getConnection("jdbc:odbc:student1");
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
ResultSet rs=null;
int p,m,n;
int PageSize=5;//页显示记录数
int RowCount=0;//总的记录数
int PageCount=0;//总页数
int ShowPage=1;//待显页码
String sql=null;
String search_txt="";
String ToPage=request.getParameter("ToPage");
if (request.getParameter("search_txt")!=null && !(request.getParameter("search_txt").equals("")))
{
search_txt=new String(request.getParameter("search_txt").trim().getBytes("8859_1"));
}
if (search_txt!=null && !(search_txt.equals("")))
{
sql="select * from xsqk where xuhao like'%"+search_txt+"%'";
sql=sql+"or xuehao like'%"+search_txt+"%'";
sql=sql+"or xingming like'%"+search_txt+"%'";
sql=sql+"or xingbie like'%"+search_txt+"%'";
sql=sql+"or xibie like'%"+search_txt+"%'";
sql=sql+"or banji like'%"+search_txt+"%'";
sql=sql+"or mingzhu like'%"+search_txt+"%'";
sql=sql+"or jiating like'%"+search_txt+"%'";
sql=sql+"or shengfeng like'%"+search_txt+"%'";
sql=sql+"or lianxi like'%"+search_txt+"%'";
sql=sql+"order by ID";
}
else
{
sql="select * from xsqk order by xuehao";
}
rs=stmt.executeQuery(sql);
rs.last();
RowCount=rs.getRow();
PageCount=((RowCount % PageSize)==0?(RowCount/PageSize):(RowCount/PageSize)+1);
if(ToPage!=null)
{
ShowPage=Integer.parseInt(ToPage);
if(ShowPage>PageCount)
{
ShowPage=PageCount;
}
else if(ShowPage<=0)
{
ShowPage=1;
}
}
rs.absolute((ShowPage-1)*PageSize+1);
%>
<font size="6">学生成绩表</font>
<%
if (search_txt!=null && !search_txt.equals(""))
{
%>
以下是包含关键字<font size="6" color="#FF0000"><%=search_txt%></font>的所有信息
<%
}
else
{
%>
以下所有信息
<%
}
%>
共<font color="#FF0000"><%=RowCount %></font>条
共<font color="#FF0000"><%=PageCount%></font>页
当前页为第<font color="#FF0000"><%=ShowPage%></font>页
<%
if(PageCount>1)
{
if(ShowPage-3>0)
{
m=ShowPage-3;
}
else
{
m=1;
}
if(ShowPage+3>PageCount)
{
n=ShowPage+3;
}
else
{
n=PageCount;
}
%>
转到页码:[
<%
for(p=m;p<=n;p++)
{
if(ShowPage==p)
{
%>
<font color="#0000FF"><b><%=p%></b></font>
<%
}
else
{
%>
<a
<%
if(ShowPage==p)
{
%>
style="color:red"
<%
}
%>
href="fenye.jsp?ToPage=<%=p%>&search_txt<%=search_txt%>"><%=p%></a>
<%
}
}
%>
]
<%
}
%>
<table align=center border=1 width=900>
<tr align=center>
<td>序号</td>
<td>学号</td>
<td>姓名</td>
<td>性别</td>
<td>系别</td>
<td>班级</td>
<td>民族</td>
<td>家庭住址</td>
<td>身份证号</td>
<td>联系电话</td>
</tr>
<%
for(int i=1;i<PageSize;i++)
{
out.println("<tr align=center>");
out.println("<td>"+rs.getString("xuhao")+"</td>");
out.println("<td>"+rs.getString("xuehao")+"</td>");
out.println("<td>"+rs.getString("xingming")+"</td>");
out.println("<td>"+rs.getString("xingbie")+"</td>");
out.println("<td>"+rs.getString("xibie")+"</td>");
out.println("<td>"+rs.getString("banji")+"</td>");
out.println("<td>"+rs.getString("mingzhu")+"</td>");
out.println("<td>"+rs.getString("jiating")+"</td>");
out.println("<td>"+rs.getString("shengfeng")+"</td>");
out.println("<td>"+rs.getString("lianxi")+"</td>");
out.println("</tr>");
if(!rs.next()) break;
}
%>
</table>
<table border="0" width="900">
<tr valign="baseline" align="center">
<td width="500"> </td>
<%
if(ShowPage!=1)
{
%>
<td width="50"><a href="fenye.jsp?ToPage=<%=1 %>&search_txt<%=search_txt%>">第一页 </a></td>
<td><a href="fenye.jsp?ToPage=<%=ShowPage-1 %>&search_txt<%=search_txt%>">上一页</a></td>
<%
}
if(ShowPage!=PageCount)
{
%>
<td width="50"><a href="fenye.jsp?ToPage=<%=ShowPage+1 %>&search_txt<%=search_txt%>">下一页</a></td>
<td><a href="fenye.jsp?ToPage=<%=PageCount %>&search_txt<%=search_txt%>">最后页</a></td>
<%
}
%>
<form action="fenye.jsp" method="post">
信息关键字搜索:
<input type="text" name="search_txt" size="17" value="<%=search_txt%>">
<input type="submit" value="搜索" name="B1">
</form>
<%
rs.close();
stmt.close();
conn.close();
}
catch(Exception e)
{
out.println(e.toString());
}
%>
</body>
</html>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询