Jsp 自定义标签 分页TagSuport

 

 <%@ taglib uri="/WEB-INF/tld/jsp_page.tld" prefix="p" %>

 

<p:page paging="${paging}" url="${pageContext.request.contextPath}/user/list.do"/>

 

jsp_page.tld:

<?xml version="1.0" encoding="UTF-8" ?>

<taglib xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"
    version="2.0">
   
  <description>Jsp page library</description>
  <display-name>jsp page</display-name>
  <tlib-version>1.0</tlib-version>
  <short-name>p</short-name>
  <uri></uri>

  <tag>
    <description>page</description>
    <name>page</name>
    <tag-class>cn.tag.jsp.JspPageTag</tag-class>
    <body-content>empty</body-content>
    <attribute>
        <description>
         page info
        </description>
        <name>paging</name>
        <required>true</required>
        <rtexprvalue>true</rtexprvalue>
        <type>java.lang.Object</type>
    </attribute>
    <attribute>
        <description>
         url
        </description>
        <name>url</name>
        <required>true</required>
        <rtexprvalue>true</rtexprvalue>
    </attribute>
   
  </tag>
   
  </taglib>

 

/*jsp分页标签*/
public class JspPageTag extends TagSupport {
 
 private String url;
 private Paging paging;


 public int doStartTag() throws JspException {
  System.out.println("*** url="+ url);
  
  StringBuffer sb = new StringBuffer(1024);
  String path=pageContext.getServletContext().getContextPath();
  /*首页、上一页、下一页、尾页*/
  sb.append("<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">")
           .append("<tr>")
           .append("<td class=\"STYLE4\" width=\"50%\">&nbsp;")
     .append("一共 ")
     .append(paging.getTotal())
     .append(" 条记录</td>");

 

你可能感兴趣的:(Jsp TagSupport)