// private Integer startPage;//首页
// private Integer endPage;//尾页
// private Integer goPage;//共几页
// private Integer totalNum;//总数条数
// private Integer pageSize = 5;//每页显示数据数
// private Integer currentNum = 0;//当前页数
// private PageHelper pageHelper;//页面辅助类
以上是属性对于首页尾页 当前页的判断 请给下代码一时之间卡住了脑子感觉晕乎
public String find() {
             if(){
}
}

解决方案 »

  1.   

    /WEB-INF/classes/applicationContext.xml分页的JSP通用页面pageman
    <%@ page language="java" contentType="text/html; charset=utf-8"
        pageEncoding="utf-8"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <script language="javaScript">
    <!--
    function Jumping()
    {
        document.PageForm.submit();
     
    }function gotoPage(pagenum)
    {
        document.PageForm.jumpPage.value=pagenum;
        document.PageForm.submit();
     
    }//-->
    </script>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Insert title here </title>
    </head>
    <body>
        每页 <%=pageCtl.getRowsPerPage()%>行
        共 <%=pageCtl.getMaxRowCount()%>行
        第 <%=pageCtl.getCurPage()%>页
        共 <%=pageCtl.getMaxPage()%>页
    <br>  <%if(pageCtl.getCurPage()==1){out.print("首页  上一页");} else{ %>
      <A href="javascript:gotoPage(1)">首页 </A>
      <A href="javascript:gotoPage( <%=pageCtl.getCurPage()-1%>)">上一页 </A>
      <%} %>
      <%if(pageCtl.getCurPage()==pageCtl.getMaxPage()){out.print("下一页  尾页");} else{ %>
      <A href="javascript:gotoPage( <%=pageCtl.getCurPage()+1%>)">下一页 </A>
      <A href="javascript:gotoPage( <%=pageCtl.getMaxPage()%>)">尾页 </A>
      <%} %>    转到第 <select name="jumpPage" onchange="Jumping()">
    <%
      for(int i=1;i <=pageCtl.getMaxPage();i++)
      {
      if(i==pageCtl.getCurPage()){
    %>
    <option selected value= <%=i%>> <%=i%> </option>
    <%}else{ %>
    <option  value= <%=i%>> <%=i%> </option>
    <%  }
      }
    %>
    </select>页</body>
    </html>分页主页面
    <%@ page language="java" contentType="text/html; charset=utf-8"
        pageEncoding="utf-8"%>
    <jsp:useBean id="pageCtl" class="page.PageBean" scope="request"> </jsp:useBean>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><%@page import="java.util.Vector"%>
    <%@page import="java.util.Enumeration"%> <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Insert title here </title>
    </head>
    <body>
    <table border=1>
    <%
        java.util.Vector v=pageCtl.getResult();
        java.util.Enumeration e = v.elements();
        while(e.hasMoreElements())
        {
        Object[] obj = (Object[])e.nextElement();
       
    %>
    <tr>
    <td align="center" width="50%"> <%=obj[0]%> </td>
    <td align="center" width="50%"> <%=obj[1]%> </td>
    </tr>
    <%} %>
    </table><%if(pageCtl.getMaxPage()!=1){ %><form id="PageForm" name="PageForm" action="/LMSTEST/ContactServlet" method="get">
    <%@ include file="/pageman.jsp" %> </form>
    <%} %>
    </body>
    </html>分页程序ContactServlet.java
    import java.io.IOException;
    import java.io.PrintWriter;import javax.servlet.RequestDispatcher;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;import page.ContactBean;
    import page.PageBean;/**
    * Servlet implementation class ContactServlet
    */
    public class ContactServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;    /**
        * Default constructor.
        */
        public ContactServlet() {
            // TODO Auto-generated constructor stub
        }/**
    * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
    */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub
    request.setCharacterEncoding("utf-8");
    response.setContentType("text/html");
    response.setCharacterEncoding("utf-8");
        PrintWriter out = response.getWriter();
    try {
    ContactBean contact = new ContactBean();
    PageBean pageCtl = contact.listData((String) request
    .getParameter("jumpPage"));
    System.out.print(pageCtl.getMaxPage());
    request.setAttribute("pageCtl", pageCtl);
    } catch (Exception e) {
    // TODO: handle exception
    e.printStackTrace();
    }
    RequestDispatcher dis = request.getRequestDispatcher("/contact.jsp");
        dis.forward(request, response);
    }/**
    * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
    */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub
    doGet(request, response);
    }}ContactBean.java
    package page;import java.sql.Connection;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    import java.util.Vector;import com.neusoft.njpro.Test;public class ContactBean {
    private Connection conn;
    Vector v;
    /**
    * 创建数据库一个连接
    * 初始化一个vector
    */
    public ContactBean()
    {
    Test test = new Test();
    conn = test.getCon();
    v = new Vector();
    }/**
    * @return 要查询的记录数
    * @throws SQLException
    */
    public int getAvailableCount() throws SQLException
    {
    int ret = 0;
    Statement stmt = conn.createStatement();
    ResultSet rset = stmt.executeQuery("select count(*) from procedure_test");
    while(rset.next())
    {
    ret = rset.getInt(1);
    }return ret;
    }/**
    * @param page获取指定页面的数据,并且封装在PageBean中返回
    * @return
    * @throws Exception
    */
    public PageBean listData(String page) throws Exception
    {
    try {
    PageBean pageBean = new PageBean(this);
    int pageNum = Integer.parseInt(page);
    Statement stmt = conn.createStatement();
    String strSql = "select * from (select rownumber() over(order by log_time) as rn,procedure_test.* from procedure_test) as t where t.rn between "
    + (pageNum * pageBean.rowsPerPage-pageBean.rowsPerPage+1)
    + " and "+ pageNum * pageBean.rowsPerPage;
    ResultSet rset = stmt.executeQuery(strSql);while (rset.next()) {Object[] obj = new Object[2];
    obj[0] = rset.getString(3);
    obj[1] = rset.getObject(4);
    v.add(obj);}
    rset.close();
    stmt.close();
    pageBean.curPage = pageNum;
    pageBean.data = v;
    return pageBean;
    } catch (Exception e) {
    e.printStackTrace();
    throw e;
    // TODO: handle exception
    }
    }public Vector getResult()
    {
    return v;
    }}PageBean.java
    package page;import java.sql.SQLException;
    import java.util.Vector;public class PageBean {
    public int getCurPage() {
    return curPage;
    }public void setCurPage(int curPage) {
    this.curPage = curPage;
    }public int getMaxPage() {
    return maxPage;
    }public void setMaxPage(int maxPage) {
    this.maxPage = maxPage;
    }public int getMaxRowCount() {
    return maxRowCount;
    }public void setMaxRowCount(int maxRowCount) {
    this.maxRowCount = maxRowCount;
    }public int getRowsPerPage() {
    return rowsPerPage;
    }public void setRowsPerPage(int rowsPerPage) {
    this.rowsPerPage = rowsPerPage;
    }public java.util.Vector getData() {
    return data;
    }public void setData(java.util.Vector data) {
    this.data = data;
    }public int curPage;            //当前是第几页
    public int maxPage;            //一共多少页
    public int maxRowCount;        //一共是多少行
    public int rowsPerPage = 5;        //每页多少行
    public java.util.Vector data;  //本页中的资料public PageBean()
    {}public void countMaxPage()    //根据总行数计算总页数
    {
        if(this.maxRowCount%this.rowsPerPage==0)
        {
        this.maxPage = this.maxRowCount/this.rowsPerPage;
        }
        else
        {
        this.maxPage = this.maxRowCount/this.rowsPerPage+1;
        }
    }public Vector getResult()
    {
    return this.data;
    }public PageBean(ContactBean contact) throws SQLException
    {
    this.maxRowCount = contact.getAvailableCount(); //得到总行数
    this.data = contact.getResult();                //得到要显示于本页的资料
    this.countMaxPage();
    }