分页标签的举例

 


/*将xx.tld文件引入JSP,在页面上写
*<page:pageTag name="userForm" property="page" method="getUserInfo" zone="sResult,editZone"/>
*/

public class PageTag extends TagSupport {//继承自TagSupport

private String name;
private String property;
private String scope;
private String method;
private String zone;

public int doStartTag() throws JspException {

JspWriter out = pageContext.getOut();
HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
Pagination page = (Pagination) RequestUtils.lookup(super.pageContext, name, property, scope);
int pageNo = page.getPageNo();
int totalPage = page.getTotalPage();
int count = page.getCount();
int prePage = page.getPrePage();
int nextPage = page.getNextPage();
int pageSize = page.getPageSize();
try {
out.println("共" + totalPage + "页&nbsp;");
out.println("当前为第" + pageNo + "页&nbsp;");
out.println("总记录为" + count + "条&nbsp;");
out.println("<a href='javascript:getPagination(" + prePage + "," + pageSize + ")'>上一页</a>&nbsp;");
out.println("<a href='javascript:getPagination(" + nextPage + "," + pageSize + ")'>下一页</a>&nbsp;");
out.println("<a href='javascript:getPagination(1," + pageSize + ")'>首页</a>&nbsp;");
out.println("<a href='javascript:getPagination(" + totalPage + "," + pageSize + ")'>尾页</a>&nbsp;");
out.println("<input type='hidden' name='ps' value='"+pageSize+"'/>\n<input type='hidden' name='pn' value='"+pageNo+"'/>");
out.println(
"\n<script>\n"
+ "function getPagination(pageNo,pageSize){\n"
+ "document.getElementById('pn').value=pageNo;\n"
+ "document.getElementById('ps').value=pageSize;\n"
+ "ajaxAnywhere.submitAJAX('"
+ method
+ "','"
+ zone
+ "');\n"
+ "}\n"
+ "</script>\n");
} catch (Exception e) {
e.printStackTrace();
throw new JspTagException ("IOException:" + e.toString());
}
return super.doStartTag();
}


public List getUserInfo(UserVO userVO,Pagination page) throws Exception {
int start = (page.getPageNo()-1)*page.getPageSize();
return getSqlMapClient().queryForList("user.getUserInfoCommon",userVO,start,page.getPageSize());
}

page.tld:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE taglib
        PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN"
       "http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd">

<taglib>
<tlibversion>1.0</tlibversion>
<jspversion>1.1</jspversion>
<shortname>application</shortname>
<info>
use for pagination
</info>
<tag>
<name>pageTag</name>
<tagclass>com.vanceinfo.user.web.PageTag</tagclass>
<bodycontent>jsp</bodycontent>
<attribute>
<name>name</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>property</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>method</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>zone</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
</taglib>

你可能感兴趣的:(jsp,Web,xml,sun)