MessageListAction 里的 perform 是这样写的: ------------------------------------------------------------------------------------ int start = Integer.parseInt(request.getParameter("start")); System.out.println ("Start:" + start); int page = 4;
// create a message list Message[] list = new Message[16]; for (int i=0; i<list.length; i++){ list[i] = new Message(i ,"message" + i); } request.setAttribute("list", list); request.setAttribute("start", new Integer(start)); request.setAttribute("page", new Integer(page));
// if there is a previous page, set the previous variable int previous = start-page; if ( previous>=0 ){ request.setAttribute("previous", new Integer(previous)); System.out.println ("previous:" + previous); }
// if there is a next page, set the next variable int next = start+page; if ( next<list.length ){ request.setAttribute("next", new Integer(next)); System.out.println ("next:" + next); }