进来的大侠仔细看看 先谢了分页工具类:package com.leatherstore.other;public class Pager {
    private int nowPager;//当前页
    private int pageSize;//每页显示的行数
    private int totalRecords;//总信息数
    private int totalPage;//总页数
    
    
public Pager() {
super();
}

public Pager getPage(String pageNum ,int totalRecords,int pageSize){
this.pageSize=pageSize;
this.totalRecords=totalRecords;
if(totalRecords%pageSize==0){//判断总页数
totalPage=totalRecords/pageSize;
}else{
totalPage=totalRecords/pageSize+1;
}
if(totalPage==0){//如果总页数等于0,总页数等于1
totalPage=1;
}
if(pageNum==null || "".equals(pageNum)){//判断pageNum为空显示当前页为第一页
nowPager=1;
}else{
try {
nowPager=Integer.parseInt(pageNum);//当前页就等于参数对应pageNum
} catch (NumberFormatException e) {
nowPager=1; //出现异常当前页也等于1
}
}
if(nowPager<1){//如果当前页小于1 当前也就等于1
nowPager=1;
}
if(nowPager>totalPage){//如果大于总页数 就等于总页数
nowPager=totalPage;
}
return this;

}

public int getNowPager() {
return nowPager;
}
public void setNowPager(int nowPager) {
this.nowPager = nowPager;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public int getTotalRecords() {
return totalRecords;
}
public void setTotalRecords(int totalRecords) {
this.totalRecords = totalRecords;
}
public int getTotalPage() {
return totalPage;
}
public void setTotalPage(int totalPage) {
this.totalPage = totalPage;
}
    
    
}分页方法:package com.leatherstore.dao.impl;import java.util.List;import org.hibernate.Query;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;import com.leatherstore.dao.FwxxDao;
import com.leatherstore.entity.Fwxx;
import com.leatherstore.other.Pager;public class FwxxDaoImpl extends HibernateDaoSupport implements FwxxDao { public int getFwxxCount() {
String hql = "select count(*) from Fwxx";
Query query = this.getSession().createQuery(hql);
return ((Number) query.uniqueResult()).intValue();
} @SuppressWarnings("unchecked")
public List<Fwxx> getFwxxList(Pager page) {
String hql = "from Fwxx order by fwid asc ";
Query query = this.getSession().createQuery(hql);
query.setFirstResult((page.getNowPager() - 1) * page.getPageSize());// 从第几条开始取
query.setMaxResults(page.getPageSize());// 取多少条
return query.list();
}}bizImpl层:package com.leatherstore.biz.impl;import java.util.List;import com.leatherstore.biz.FwxxBiz;
import com.leatherstore.dao.FwxxDao;
import com.leatherstore.entity.Fwxx;
import com.leatherstore.other.Pager;public class FwxxBizImpl implements FwxxBiz { private FwxxDao fwxxDao;

public void setFwxxDao(FwxxDao fwxxDao) {
this.fwxxDao = fwxxDao;
} public int getFwxxCount() {
return fwxxDao.getFwxxCount();
} public List<Fwxx> getFwxxList(Pager page) {
return fwxxDao.getFwxxList(page);
}}
接口都没贴出来action:/*
 * Generated by MyEclipse Struts
 * Template path: templates/java/JavaClass.vtl
 */
package com.leatherstore.struts.action;import java.util.List;import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;import com.leatherstore.biz.FwxxBiz;
import com.leatherstore.entity.Fwxx;
import com.leatherstore.other.Pager;
import com.leatherstore.struts.form.FwxxForm;/**
 * MyEclipse Struts Creation date: 11-01-2010
 * 
 * XDoclet definition:
 * 
 * @struts.action path="/fwxx" name="fwxxForm" input="/form/fwxx.jsp"
 *                scope="request" validate="true"
 */
public class FwxxAction extends Action {
/*
 * Generated Methods
 */
private FwxxBiz fwxxBiz; public void setFwxxBiz(FwxxBiz fwxxBiz) {
this.fwxxBiz = fwxxBiz;
} //分页属性
private String pageNum;
private String pageSize;
private int totalRecords;

public String getPageNum() {
return pageNum;
} public void setPageNum(String pageNum) {
this.pageNum = pageNum;
} public String getPageSize() {
return pageSize;
} public void setPageSize(String pageSize) {
this.pageSize = pageSize;
} public int getTotalRecords() {
return totalRecords;
} public void setTotalRecords(int totalRecords) {
this.totalRecords = totalRecords;
}
/**
 * Method execute
 * @param mapping
 * @param form
 * @param request
 * @param response
 * @return ActionForward
 */
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
FwxxForm fwxxForm = (FwxxForm) form;
    Pager page=null;
    try {
page =new Pager().getPage(pageNum, fwxxBiz.getFwxxCount(), Integer.parseInt(pageSize));
} catch (Exception e) {
page =new Pager().getPage(pageNum, fwxxBiz.getFwxxCount(), 4);
}
List<Fwxx> fwxxList=fwxxBiz.getFwxxList(page);
request.setAttribute("fwxx", fwxxList);
request.setAttribute("page", page);
return mapping.findForward("showFwxx");
}
}
页面:<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>"> <title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<style type="text/css">
.hand {
cursor: pointer;
}
</style>
<script type="text/javascript">
   //首页
function firstPage(){
var num = document.getElementById("hiddenPageNum");
if("" != null){
num.value = 1;
document.forms[0].submit();
}
}

//上一页
function prePage(){
var num = document.getElementById("hiddenPageNum");
if("" != null){
num.value = num.value - 1;
document.forms[0].submit();
}
}

//下一页
function nextPage(){
var num = document.getElementById("hiddenPageNum");
if("" != null){
num.value = num.value - 0 + 1;
document.forms[0].submit();
}
}

//末页
function lastPage(){
var num = document.getElementById("hiddenPageNum");
if("" != null){
num.value = ${page.totalPage};
document.forms[0].submit();
}
}
  
</script>
</head> <body>
<form action="/sshpager/fwxx.do">
<table>
<tr>
<td>
Title
</td>
<td>
Zj
</td>
<td>
Lxr
</td>
<td>
Date
</td>
</tr>
<logic:iterate id="fwxx" name="fwxx">
<tr>
<td>
${fwxx.title }
</td>
<td>
${fwxx.zj }
</td>
<td>
${fwxx.lxr }
</td>
<td>
${fwxx.date }
</td>
</tr>
</logic:iterate>
</table>
<div>
<span class="hand" onclick="firstPage()">首页</span>
<span class="hand" onclick="prePage()">上一页</span>
<span class="hand" onclick="nextPage()">下一页</span>
<span class="hand" onclick="lastPage()">末页</span>
${page.nowPager}/${page.totalPage}
</div>
<input type="hidden" name="pageNum" value="${page.nowPager }" id="hiddenPageNum">
</form>
</body>
</html>
好了  终于贴完了Title  Zj  Lxr  Date  
北大附近招合租  1000.0  周星星  2007-07-03 09:38:09.0  
健翔桥一居出租了  1200.0  刘景杨  2007-07-03 10:01:00.0  
出租2居  2100.0  伊先生  2007-07-03 01:04:05.0  
便宜出租前门四合院  2500.0  赵大宝  2007-07-03 01:10:29.0  首页 上一页 下一页 末页 1/3 
 为什么我点下一页的时候不能提交显示下一页的内容  

解决方案 »

  1.   

    “不能提交显示下一页的内容”是什么意思?是不能提交啊,还是不能显示?
    你后台Action看看是否得到正确的页码~~ps,你这个分页写的有意思,直接用超链接的形式去提交不好嘛?比你又用隐藏域,又用JS的简单很多~
      

  2.   


     function nextPage(){
                var num = document.getElementById("hiddenPageNum");
                if("" != null){
                    num.value = num.value - 0 + 1;
                    document.forms[0].submit();
                }
            }
    你alert下 看num.value的值取到没
    肯定是当前页 这个变量的 取值传值问题
      

  3.   

    num.value = num.value - 1;
    alert(num.value);
    打印出来看看,貌似不能这样减吧。
      

  4.   

    能alert出来  我试过了
      

  5.   

    LZ你那是struts2的写法,所以没有想要的数据,请更改方法即可!
      

  6.   

    什么意思? 我意思是你 看下你分页时传的值是不是有问题
    即 刚进去是在第一页 你点下一页 就该传2吧 然后你看你根据每页大小取出的结果集是否正确
    DEBUG 跟踪下 主要跟踪查询前的参数 和 返回的结果集
      

  7.   


    你后台Action是干嘛的,看看页码有没有提交到Action里,request里的数据有没有更新~
      

  8.   

    谢谢大家了   原因是 action里没有取到隐藏域的值 谢了
      

  9.   

    你讲的对  我该了  action里也改了   获取了隐藏域的值了
      

  10.   

    你讲的对 我该了 action里也改了 获取了隐藏域的值了   上楼的引用错了
      

  11.   

    我最近一直在研究SSH分页,你能把这个分页源码给我发一份吗?谢谢![email protected]
      

  12.   

    我想要源码,急求源码。非常感谢。邮箱:[email protected]