1、private String page_cnt = "2";public void setPages(String pages) {
this.pages = pages;
} public String getPage_cnt() {
System.out.println(this.page_cnt+"---------");
return page_cnt;
}
private void set_pagedata(AP2000Form ap2000Form, int MaxPage){
int nowpage = Integer.parseInt(ap2000Form.getPage_cnt());
int pages = 1;
pages = MaxPage / Integer.parseInt(ap2000Form.getPage_num());
if(MaxPage % Integer.parseInt(ap2000Form.getPage_num()) > 0){
pages++;
}
if(nowpage > pages){
nowpage--;
ap2000Form.setPage_cnt(String.valueOf(nowpage));
}
ap2000Form.setPages(String.valueOf(pages));
} public ActionForward default_execute(ActionMapping mapping, AP2000Form ap2000Form, HttpServletRequest request, HttpServletResponse response, Connection conn) throws SQLException {
AP2000DAO dao = new AP2000DAO();
List<AP2000Bean> list = null;
int count = dao.getTotal(conn);
//分页

ap2000Form.setTotals(count);
set_pagedata(ap2000Form, count);
list = dao.getTopicList(ap2000Form,conn);
request.setAttribute("UserList", list);

return mapping.findForward(PAGE_01);
}public List<AP2000Bean> getTopicList(AP2000Form ap2000Form,Connection conn) throws SQLException{
PreparedStatement pstmt = null;
ResultSet rs = null;
List<AP2000Bean> list = null;
//int page_num = Integer.parseInt(ap2000Form.getPage_num()); // 每页显示的条数
int page_num =1;
int pageCnt = Integer.parseInt(ap2000Form.getPage_cnt()); // 当前页数
System.out.println(pageCnt+"[[[[[[[");------为什么这里等于1?,我上面的form里面的属性没有用static修饰就不会保存值(就算在上面set_pagedata()这个方法里进行了--但是调用另一个方法,值任然是2,我别的类不会出现这个情况,唯独这个类出现了,怪事,麻烦帮帮看看),应该还是而

int recordCntFrom = page_num * (pageCnt - 1); // 每页的开始记录

//进行分页查询
String sql_mysql = "SELECT TOPIC_ID,TOPIC_NAME,TOPIC_COMMENT,CONTENT,LINK_URL,URL,PIC,CREATE_USER,CREATE_TIME " +
"FROM TOPIC ORDER BY CREATE_TIME DESC LIMIT "+recordCntFrom+","+page_num;
。后面许多,我没写,也有影响System.out.println(pageCnt+"[[[[[[[");------为什么这里等于1?,我上面的form里面的属性没有用static修饰就不会保存值(就算在上面set_pagedata()这个方法里进行了--但是调用另一个方法,值任然是2,我别的类不会出现这个情况,唯独这个类出现了,怪事,麻烦帮帮看看),应该还是而

解决方案 »

  1.   

    private void set_pagedata(AP2000Form ap2000Form, int MaxPage){
            int nowpage = Integer.parseInt(ap2000Form.getPage_cnt());
            int pages = 1;
            pages = MaxPage / Integer.parseInt(ap2000Form.getPage_num());
            if(MaxPage % Integer.parseInt(ap2000Form.getPage_num()) > 0){
                pages++;
            }
            if(nowpage > pages){
                nowpage--;
                ap2000Form.setPage_cnt(String.valueOf(nowpage));
            }
            ap2000Form.setPages(String.valueOf(pages));
        }很有可能是这个方法里的最后一句话改变的。因为他是set开头的。