现小弟要实现一个分页效果 用Struts2 但是怎么都实现不出来?在Action中
HttpServletRequest request=ServletActionContext.getRequest();
HttpSession session=request.getSession(false);
Object count= session.getAttribute("counter");
int p=3; //第几页
public String updown(){
if(count==null)
{
p=3;
session.setAttribute("counter", new Integer(p));
}
else if(pagebean.getUp()==1) //如果是下一页
{
p=((Integer)count).intValue();
p=p+1;
session.setAttribute("counter", new Integer(p));
}
else if(pagebean.getUp()==0) //如果是下一页
{
p=((Integer)count).intValue();
p=p-1;
session.setAttribute("counter", new Integer(p));
}
updown2();
return "updown";
}
public void updown2(){

p=((Integer)count).intValue();
listpage=sen.QuryAll(p,3);
session.setAttribute("listpages", listpage);
}
在jsp页面中单击<a href="<s:url action='updown'/>?pagebean.up=1">下一页</a>
              <a href="<s:url action='updown'/>?pagebean.up=0">上一页</a> 进入都updown()方法但是报了个错误
严重: Servlet.service() for servlet default threw exception
Unable to instantiate Action, com.action.PageAction,  defined for 'updown' in namespace ''null - action - file:/E:/apache-tomcat-6.0.0/webapps/text_0/WEB-INF/classes/struts2.xml:9:75

解决方案 »

  1.   

    无法实例化Action,updown定义了没有?
      

  2.   

    给你一个分页的类:
    public class DividePage {
    public static int totalRecord;
    public static int pageCount;
    @SuppressWarnings("unchecked")
    public static <T>T getList(Integer pageSize,Integer currentPage,List<T> list){
    int totalrecord;
    int pagecount;
    totalrecord = list.size();
    pagecount=(totalrecord+pageSize-1)/pageSize;
    List<T> list1 = new ArrayList<T>();
    if(currentPage==null){
    currentPage=1;
    }
    if(currentPage<pagecount){
    for(int i=(currentPage-1)*pageSize;i<currentPage*pageSize;i++){
    list1.add(list.get(i));
    }
    }
    //修改
    if(currentPage>=pagecount && totalrecord != 0){
    currentPage=pagecount;
    for(int i=(currentPage-1)*pageSize;i<totalrecord;i++){
    list1.add(list.get(i));
    }
    }

    totalRecord = totalrecord;
    pageCount = pagecount;
    return (T)list1;
    }
    }
      

  3.   

    补充一点: 在action中你查询到数据集后,调用该方法就得到分段的数据了