java 分页(2)

来源:互联网 发布:网络分为几种类型 编辑:程序博客网 时间:2024/05/29 16:57

list.jsp

 

 

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@page import="com.stu.dao.StudentDAO"%>
<%@page import="com.stu.entity.*"%>
 
<html>
  <head>
     
  </head>
 
  <body>
  <table border="1">
       <tr>
           <th>学号</th>
           <th>姓名</th>
           <th>性别</th>
           <th>年龄</th>
           <th>生日</th>
           <th>分数</th>
       </tr>
       <%
           StudentDAO studao =new StudentDAO();
           int currentPage =1;
           String p =request.getParameter("page");
           try{
             currentPage =Integer.parseInt(p);
           }catch(Exception e){
             currentPage=1;
           }
          
           List<Student> list=  studao.queryStudentByPage(currentPage);
           for(int i=0;i<list.size();i++)
           {
                %>
                  <tr>
                     <td><%=list.get(i).getId()%></td>
                     <td><%=list.get(i).getStuName()%></td>
                     <td><%=list.get(i).getStuSex()%></td>
                     <td><%=list.get(i).getStuAge()%></td>
                     <td><%=list.get(i).getBirthDay()%></td>
                     <td><%=list.get(i).getScore()%></td>
                  </tr>
                <%
           }
        %>
        <tr>
           <td colspan="6"><input type="button" value="上一页" onclick="turnPage(-1)"><input type="button" value="下一页" onclick="turnPage(1)"></td>
        </tr>
     </table>
     <input type="hidden" id="cp" value="<%=currentPage%>">
  </body>
  <script>
         function turnPage(p){
             var ccp =document.getElementById("cp").value;
             var np =parseInt(ccp)+parseInt(p);
             window.location.href="http://localhost:8080/stu/list.jsp?page="+np;
         }
      </script>
</html>

原创粉丝点击