Jsp分页显示代码实现 (

<%@ page language="java" import="java.sql.*,java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>



 
   
   
    My JSP 'Fenye.jsp' starting page
   
   
   
   
   
   
   
   
 
 
 
    <%
    int i = 1;
    int count = 0;  //总信息数
    int totalPageCount = 0; //总页数
    int perPageCount = 5; //每页显示信息数
    int currentPage = 1;//当前页数
    String pageId = request.getParameter("page");
    if(pageId != null)
    {
     try{currentPage = Integer.parseInt(pageId);}

     catch(Exception e){}
    }
    com.allan.Test test = new com.allan.Test();
    ResultSet rs = test.query("select * from student");
    rs.last();
    count = rs.getRow();
    if(count % perPageCount == 0)
    {
     totalPageCount = count/perPageCount;
    }
    else{
     totalPageCount = count/perPageCount + 1;
     }
    int currentIndex = (currentPage - 1)*perPageCount + 1;//当前页显示的第一条记录
    if(count > 0)
    {
     rs.absolute(currentIndex);
     
    } 
    %>
 


 

 

 

 <%
 while(rs.next())
 {
 %>
 

 

 

 <%
 i++;
 if(i > perPageCount-1) break;
 }
 %>
 
<%=rs.getString(1)%><%=rs.getString(2)%>
<%=rs.getString(1)%><%=rs.getString(2)%>

 
 
 
  
  

 <%
 String firstLink,lastLink,preLink,nextLink;
 firstLink ="Fenye.jsp?page=1";
 lastLink ="Fenye.jsp?page="+totalPageCount;
 if(currentPage>1)
 {
  preLink = "Fenye.jsp?page="+(currentPage-1);
 }
 else
 {
  preLink = firstLink;
 }
 if(currentPage<=totalPageCount-1)
 {
  nextLink ="Fenye.jsp?page="+(currentPage+1);
 }
 else
 {
  nextLink = lastLink;
 }
 %>
 

  


  共<%=count%>
  第<%=currentPage%>页/共
  <%=totalPageCount%>页|
  >首页 |
  >上一页 |
  >下一页
  >尾页 |
  转到
  


  

  

 

你可能感兴趣的:(Jsp分页显示代码实现 ()