日期:2014-05-18  浏览次数:20726 次

问一下jsp分页显示的方法!!!!!
jsp中是如何实现数据的分页显示的,,谢了

------解决方案--------------------
还有 :http://blog.csdn.net/hbuzhang/archive/2004/12/07/207202.aspx
很多的自己去看把

------解决方案--------------------
还可以用newxy实现
------解决方案--------------------
<%@page import= "java.sql.* "%>
<%@ page language= "java " import= "java.util.* "%>
<%@page contentType= "text/html;charset=gb2312 "%>
<html>
<head>
<link href= "css/main.css " rel= "stylesheet " type= "text/css ">
<link href= "css/text.css " rel= "stylesheet " type= "text/css ">
<title> test </title>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 "> <style type= "text/css ">

<!--
body {
margin-top: 5px;
}
-->
</style>
<script type= "text/JavaScript ">
<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
eval(targ+ ".location= ' "+selObj.options[selObj.selectedIndex].value+ " ' ");
if (restore) selObj.selectedIndex=0;
}
//-->
</script>
</head>
<body>

<%
int intPageSize = 20; //一页显示的记录数
int intRowCount ; //记录总数
int intPageCount ; //总页数
int intPage ; //待显示页码
java.lang.String strPage;
int i;
//取得待显示页码
strPage = request.getParameter( "page ");

Class.forName( "com.microsoft.jdbc.sqlserver.SQLServerDriver ").newInstance();
String url= "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=test ";
//pubs为你的数据库的
String user= "sa ";
String password= "sa ";
Connection con=DriverManager.getConnection(url,user,password);
Statement stmt=con.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,java.sql.ResultSet.CONCUR_READ_ONLY);
String querystring= "select * from tp_jtq " ;
ResultSet rs = stmt.executeQuery(querystring);



if(strPage==null){//表明在QueryString中没有page这一个参数,此时显示第一页数据
intPage = 1;
}
else{//将字符串转换成整型
intPage = java.lang.Integer.parseInt(strPage);
if(intPage <1) intPage = 1;
}
rs.last();
intRowCount = rs.getRow();
//记算总页数
intPageCount = (intRowCount+intPageSize-1) / intPageSize;
//调整待显示的页码
if(intPage> intPageCount) intPage = intPageCount;
if(intPageCount> 0){
//将记录指针定位到待显示页的第一条记录上
rs.absolute((intPage-1) * intPageSize + 1);
//显示数据

%>
<table width= "98% " border= "0 " cellpadding= "2 " cellspacing= "1 " class= "TableBody " align= "center ">
<tr align= "center "bgcolor= "#9DCEFF " class= "TableHeader ">
<td> 姓名 </td>
<td> 年龄 </td>
<td> 出生年月 </td>
<td> 性别 </td>
</tr>
<%
i = 0;
while(i <intPageSize && !rs.isAfterLast()){%>
<tr bgcolor= "#ffffff ">
<td> <a href= "dyGuarantee.jsp?ID= <%=rs.getString(1)%> "> <%= rs.getString( "bbill ")%> </a>