messagelist.do - > messagelist.jsp
用 messagelist.do?start=0 来显示第一个页面
参数说明:
list:信息列表
start:开始位置
page:每页显示的信息数目
previous:上页开始位置
next:下页开始位置
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);
}
return (mapping.findforward("success"));
------------------------------------------------------------------------------------
下面是 messagelist.jsp 里的内容:
------------------------------------------------------------------------------------
< logic:iterate id="message" name="list" offset="start" length="page" >
< br >< html:link
paramid="id" paramname="message" paramproperty="id"
page="/messagedetail.do" >
< bean:write name="message" property="name" / >
< /html:link >
< /logic:iterate >
< logic:present name="previous" >
< br >< html:link
paramid="start" paramname="previous"
page="/messagelist.do" >
上一页
< /html:link >
< /logic:present >
< logic:present name="next" >
< br >< html:link
paramid="start" paramname="next"
page="/messagelist.do" >
下一页
< /html:link >
< /logic:present >
------------------------------------------------------------------------------------
以此例子来说明 logic:iterate 在分页里的用法
由于每次 messagelist.do 都会处理所有的 message,所以性能上还是可以再优化
比如把 message 数组存放在 session 里。
新闻热点
疑难解答