日期:2014-05-17  浏览次数:20847 次

servlet 分页 不知道怎么的,他就不显示第一条
Java code
package com.soft.mcz;
import javax.servlet.http.*;
import java.io.*;
import java.sql.*;

public class Wel extends HttpServlet{
    public void doGet(HttpServletRequest req,HttpServletResponse res){
        Connection con=null;
        Statement st=null;
        ResultSet rs=null;
        PreparedStatement pst=null;
        try{
            
            Class.forName("com.mysql.jdbc.Driver").newInstance();
            con =DriverManager.getConnection("jdbc:mysql://localhost/database1","root","jacob");
            st=con.createStatement();
            
            
            
            res.setContentType("text/html;charset=gb2312");
            PrintWriter pw = res.getWriter();
            String nn=req.getParameter("username");
            HttpSession hs=req.getSession(true);
            ;
            
            String name=(String)(hs.getAttribute("name"));
            pw.println(name+"欢迎您登录本系统!!!</br>");
            pw.println("<image src=images/im.png>");
            
            int pageSize=3 ;
            int pageCount=0;
            int pageNow=1;
            int countSize=0;
            String sql2="select count(*) from up";
            rs=st.executeQuery(sql2);
            if(rs.next()){
                countSize=rs.getInt(1);
                }
            if(countSize%pageSize==0){
                pageCount=countSize/pageSize;
                
                }
            else{
                pageCount=countSize/pageSize+1;
                }
        pw.println(countSize);
                
            pw.println("<table border=3>");
            pw.println("<tr>");
            pw.println("<th>姓名</th>");
            pw.println("<th>密码</th>");
            pw.println("</tr>");
        //    String sql="select * from up order by username asc LIMIT ?,?";
            //(pageNow-1)*pageSize+","+pageSize;
            
            pst=con.prepareStatement("select * from up order by username asc LIMIT ?,?");
            pst.setInt(1,(pageNow-1)*pageSize);
            pst.setInt(2,pageSize);            
            rs=pst.executeQuery();
            int i= rs.getRow();
            pw.println(i);
            
            if(rs.next()){
            
            while(rs.next()){
            //    pw.println("测试点2");
                pw.println("<tr>");
                pw.println("<td>"+rs.getString(1)+"</td>");
                pw.println("<td>"+rs.getString(2)+"</td>");
                pw.println("</tr>");
                
                }
                
            }else{
            pw.println("buchenggong ");    
            }
            pw.println("</table>");
            
        
        }catch(Exception e){
            e.getStackTrace();
                }
        finally{
                    try{
                        rs.close();
                        st.close();
                        con.close();
                        }
                        catch(Exception ee){
                        
                        }
                    
                    }
    
        }
        public void doPost(HttpServletRequest req,HttpServletResponse res){
            
            this.doGet(req,res);
            }
        
    }


本来我的意想是每页显示3条记录,但是怎么调试都只有两条
用的数据库是mysql
开发工具是JCreateor
谢谢各位大侠的请教

姓名 密码 
test2 test2 
test3 test3 



------解决方案--------------------
rs.nex