• 分页


    分页show.jsp

    <%--
    分页操作
    <a href="serlect_all?pageindex=${pu.present_page_num>1?pu.present_page_num-1:1}">上一页</a>
    <c:forEach var="i" begin="1" end="${pu.total_page_num}">
    
        <a href="serlect_all?pageindex=${i}">${i}</a>
    
    </c:forEach>
    <a href="serlect_all?pageindex=${pu.present_page_num+1}">下一页</a>
    --%>

    pageUtils

    package com.zym.utils;
    
    public class pageUtils {
        private int total_page_num;
        private int present_page_num;
        private int num_of_onepage;
        private int total_num;
    
    
        public int getTotal_num() {
            return total_num;
        }
    
        public void setTotal_num(int total_num) {
            this.total_num = total_num;
        }
    
        public pageUtils() {
        }
    
        public pageUtils(int total_page_num, int present_page_num, int num_of_onepage, int total_num) {
            this.total_page_num = total_page_num;
            this.present_page_num = present_page_num;
            this.num_of_onepage = num_of_onepage;
            this.total_num = total_num;
        }
    
        public int getTotal_page_num() {
            System.out.println(total_page_num+"=================");
            return total_page_num;
        }
    
        public void setTotal_page_num(int total_page_num) {
            this.total_page_num = total_page_num;
        }
    
        public int getPresent_page_num() {
            return present_page_num;
        }
    
        public void setPresent_page_num(int present_page_num) {
            this.present_page_num = present_page_num;
        }
    
        public int getNum_of_onepage() {
            return num_of_onepage;
        }
    
        public void setNum_of_onepage(int num_of_onepage) {
            this.num_of_onepage = num_of_onepage;
        }
    
        @Override
        public String toString() {
            return "pageUtils{" +
                    "total_page_num=" + total_page_num +
                    ", present_page_num=" + present_page_num +
                    ", num_of_onepage=" + num_of_onepage +
                    '}';
        }
    
    //    public
    
    
    
    
    
    }

    UserDao

        public  List<User> SelectAll(pageUtils pu) throws SQLException, ClassNotFoundException {
            List<User> users = new ArrayList<>();
            conn = jdbcUtils.get_conn();
             pstt = conn.prepareStatement("select * from user limit ?,? ");
    //         pstt = conn.prepareStatement("show tables ");
    //        pstt.set;
            pstt.setInt(1,((pu.getPresent_page_num()-1)*pu.getNum_of_onepage()));
            pstt.setInt(2, pu.getNum_of_onepage());
    
            rs = pstt.executeQuery();
             User u =null;
             while (rs.next()){
                 u = new User(rs.getInt("id"),rs.getString("name"),rs.getInt("age"));
                 users.add(u);
             }
    
             jdbcUtils.close_all(conn,pstt,rs);
            return users;
        }

    servlet

     try {
                UserDao userDao = new UserDao();
    
    
    
                //总页数
                //总条数
                //当前页数
                //一页有多少条
    
                //总条数
                int total_num = userDao.select_count();
                System.out.println("总条数"+total_num);
    
                //总页数
                int total_page_num = 2;
    
                //当前页数默认为1
    
                int present_page_num =1;
                if (request.getParameter("pageindex")!=null) {
                    present_page_num=Integer.parseInt(request.getParameter("pageindex"));
                    System.out.println(present_page_num+"1111111");
                }
    
                //一页有多少条
                int num_of_onepage = total_num/total_page_num;
    
                pageUtils pageUtils_obj = new pageUtils(total_page_num,present_page_num,num_of_onepage,total_num);
                System.out.println(pageUtils_obj.getTotal_page_num()+"---------------");
                request.setAttribute("pu", pageUtils_obj);
    
                List<User> users = userDao.SelectAll(pageUtils_obj);
    //            boolean res = new UserDao().crete_table();
    //            System.out.println(res+"=======================");
                request.setAttribute("users",users );
    
    
    
            } catch (SQLException e) {
                e.printStackTrace();
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            }
            request.getRequestDispatcher("show.jsp").forward(request,response);
    
    
    //    }

     

     

  • 相关阅读:
    Lesson 3 Nehe
    Lesson 2 Nehe
    Lesson 1 Nehe
    Lesson 1 Nehe
    JavaScript 字符串与数组转换函数[不用split与join]
    华中科大校长:教授被称为“叫兽”是教育的悲哀
    /etc/profile、~/.bash_profile等几个文件的执行过程
    cygwin下遇到system没有执行的问题
    发短信 汉字编码 utf-8 UCS-2BE
    UTF-8与UNICODE的关系及代码转换
  • 原文地址:https://www.cnblogs.com/taozizainali/p/11070133.html
Copyright © 2020-2023  润新知