现在的位置: 首页 > 综合 > 正文

jsp分页显示代码

2014年02月08日 ⁄ 综合 ⁄ 共 2427字 ⁄ 字号 评论关闭

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

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
  
    <title>My JSP 'Fenye.jsp' starting page</title>
  
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
  
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->
  </head>
 
  <body>
    <%
    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);
    
    }
    %>
 <TABLE>
 <tr align = "center">
 <td><%=rs.getString(1)%></td>
 <TD><%=rs.getString(2)%></TD>
 <%
 while(rs.next())
 {
 %>
 <tr align = "center">
 <td><%=rs.getString(1)%></td>
 <TD><%=rs.getString(2)%></TD>
 <%
 i++;
 if(i > perPageCount-1) break;
 }
 %>
 </TABLE >
 <TABLE width ="90%" border = 0>
 <tr align = "right" valign = "top">
 <td colspan ="4" align = "right">
 <%
 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;
 }
 %>
 <form method ="post" action="Fenye.jsp">
  <p align = "center">
  共<font color="#0000FF"><%=count%></font>条
  第<font color="#0000FF"><%=currentPage%></font>页/共
  <font color="#0000FF"><%=totalPageCount%></font>页|
  <a href=<%=firstLink%>>首页</a> |
  <a href=<%=preLink%>>上一页</a> |
  <a href=<%=nextLink%>>下一页</a>
  <a href=<%=lastLink%>>尾页</a> |
  转到<input type "text" name = page size = 2><input type="submit" name=submit value=GO>
  </p>
  </form>
  </td>
  </tr>
  </TABLE>
  </body>
</html>

 

抱歉!评论已关闭.