Posted on 2008-08-06 22:28
G_G 阅读(1522)
评论(0) 编辑 收藏 所属分类:
JspTag
->
http://displaytag.sourceforge.net分页流程描述:
1.组合查询参数得取。
比如时间范围,用户名模糊查询。。这些存入 session->data;name
2.通过持久层得到 ‘数据总条数’‘当前展现页数据’;
3.分页点击;根据session 组合参数,再次向数据库申请书及。
代码:
<jsp:root version="1.2" xmlns:jsp="http://java.sun.com/JSP/Page"
xmlns:display="urn:jsptld:http://displaytag.sf.net">
<jsp:directive.page import="java.util.regex.Pattern" />
<jsp:directive.page import="test.Bean" />
<jsp:directive.page import="java.util.ArrayList" />
<jsp:directive.page import="java.util.List" />
<jsp:directive.page contentType="text/html; charset=UTF-8" />
<jsp:include page="inc/header.jsp" flush="true" />
<jsp:scriptlet> <![CDATA[
Pattern pattern = Pattern.compile("d-[0-9]+-p");
String pageIndexName = null ;
for(Object otmp : request.getParameterMap().keySet() ){
if( pattern.matcher(otmp.toString()).find() ){
pageIndexName = otmp.toString();
break;
}
}
int pageSize = 10; //每页显示的条数
int pageIndex = 0 ;
if(pageIndexName!=null){
pageIndex = (request.getParameter(pageIndexName)==null)?
0:(Integer.parseInt(request.getParameter(pageIndexName)) - 1); //当前页数
}
List list = new ArrayList();
for(int i=0;i<pageSize;i++){
list.add( new Bean(pageIndex*10+i,"liu-"+pageIndex*10+i) );
}
request.setAttribute("data",list);
session.setAttribute( "resultSize", 100 );
out.print("!"+pageIndexName);
]]></jsp:scriptlet>
<h2>数据分页展现开始</h2>
<display:table name="data" pagesize="10" partialList="true"
size="sessionScope.resultSize">
<display:column property="id" title="ID"></display:column>
<display:column property="name" title="名字"></display:column>
</display:table>
<jsp:include page="inc/footer.jsp" flush="true" />
</jsp:root>