`
sunguanxing
  • 浏览: 1105664 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

struts 分页标签

阅读更多
实现自定义struts2标签分三个部分:

1.定义标签 在这步要创建标签说明文件 *.tld

2.实现标签组件 这里只需继承struts2中的组件类和标签类就行了

3.用freemarker渲染标签 这步要创建一个*.ftl文件.同时我把相关分页逻辑也写在了这里

下面是效果图



下面是源代码:

在/web-inf下建立tlds文件夹,在其中新建iThink.tld文件(名字随个人喜好),内容如下:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>      
<!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN" "http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd">      
<taglib>      
  <tlib-version>2.2.3</tlib-version>      
  <jsp-version>1.2</jsp-version>      
  <short-name>ithink</short-name>      
  <uri>/ithink-tags</uri>      
  <display-name>"iThink Tags"</display-name>      
  <description><![CDATA["iThink is a student team. iThink Tags supports custom components that usually used in web develop"]]></description>      
  <tag>      
    <name>pager</name>      
    <tag-class>org.icim.pager.struts2.PagerTag</tag-class>      
    <body-content>JSP</body-content>      
           
    <attribute>      
      <name>totalRecord</name>      
      <required>false</required>      
      <rtexprvalue>true</rtexprvalue>      
      <description><![CDATA[总记录数]]></description>      
    </attribute>      
               
    <attribute>      
      <name>totalPage</name>      
      <required>true</required>      
      <rtexprvalue>true</rtexprvalue>      
      <description><![CDATA[总页数]]></description>      
    </attribute>      
      
    <attribute>      
      <name>curPage</name>      
      <required>true</required>      
      <rtexprvalue>true</rtexprvalue>      
      <description><![CDATA[当前页号]]></description>      
    </attribute>      
      
    <attribute>      
      <name>pageLimit</name>      
      <required>false</required>      
      <rtexprvalue>true</rtexprvalue>      
      <description><![CDATA[每版最多显示的页数,最好为奇数]]></description>      
    </attribute>      
               
    <attribute>      
      <name>url</name>      
      <required>true</required>      
      <rtexprvalue>true</rtexprvalue>      
      <description><![CDATA[翻页时的请求地址,如:list?page={page},其中的{page}会被动态地替换]]></description>      
    </attribute>      
               
    <attribute>      
      <name>curCssClass</name>      
      <required>false</required>      
      <rtexprvalue>true</rtexprvalue>      
      <description><![CDATA[当前页的span标签的cssClass]]></description>      
    </attribute>      
      
    <attribute>      
      <name>showTotalPage</name>      
      <required>false</required>      
      <rtexprvalue>true</rtexprvalue>      
      <description><![CDATA[是否显示总页数,默认为"true"]]></description>      
    </attribute>      
               
    <attribute>      
      <name>showTotalRecord</name>      
      <required>false</required>      
      <rtexprvalue>true</rtexprvalue>      
      <description><![CDATA[是否显示总记录数,只有设置了总记录数属性的时候才有效,默认为"false"]]></description>      
    </attribute>      
      
    <attribute>      
      <name>directJumpType</name>      
      <required>false</required>      
      <rtexprvalue>true</rtexprvalue>      
      <description><![CDATA[直接跳转的方式,"goto"或"select",默认为none]]></description>      
    </attribute>      
           
    <!--以下是原UIBean通用的属性-->      
    <attribute>      
      <name>accesskey</name>      
      <required>false</required>      
      <rtexprvalue>false</rtexprvalue>      
      <description><![CDATA[Set the html accesskey attribute on rendered html element]]></description>      
    </attribute>      
           
    <attribute>      
      <name>cssClass</name>      
      <required>false</required>      
      <rtexprvalue>false</rtexprvalue>      
      <description><![CDATA[The css class to use for element]]></description>      
    </attribute>      
    <attribute>      
      <name>cssStyle</name>      
      <required>false</required>      
      <rtexprvalue>false</rtexprvalue>      
      <description><![CDATA[The css style definitions for element to use]]></description>      
    </attribute>      
    <attribute>      
      <name>disabled</name>      
      <required>false</required>      
      <rtexprvalue>false</rtexprvalue>      
      <description><![CDATA[Set the html disabled attribute on rendered html element]]></description>      
    </attribute>      
    <attribute>      
      <name>id</name>      
      <required>false</required>      
      <rtexprvalue>false</rtexprvalue>      
      <description><![CDATA[id for referencing element. For UI and form tags it will be used as HTML id attribute]]></description>      
    </attribute>      
    <attribute>      
      <name>key</name>      
      <required>false</required>      
      <rtexprvalue>false</rtexprvalue>      
      <description><![CDATA[Set the key (name, value, label) for this particular component]]></description>      
    </attribute>      
    <attribute>      
      <name>label</name>      
      <required>false</required>      
      <rtexprvalue>false</rtexprvalue>      
      <description><![CDATA[Label expression used for rendering a element specific label]]></description>      
    </attribute>      
    <attribute>      
      <name>labelposition</name>      
      <required>false</required>      
      <rtexprvalue>false</rtexprvalue>      
      <description><![CDATA[Define label position of form element (top/left)]]></description>      
    </attribute>      
    <attribute>      
      <name>name</name>      
      <required>false</required>      
      <rtexprvalue>false</rtexprvalue>      
      <description><![CDATA[The name to set for element]]></description>      
    </attribute>      
    <attribute>      
      <name>onblur</name>      
      <required>false</required>      
      <rtexprvalue>false</rtexprvalue>      
      <description><![CDATA[ Set the html onblur attribute on rendered html element]]></description>      
    </attribute>      
    <attribute>      
      <name>onchange</name>      
      <required>false</required>      
      <rtexprvalue>false</rtexprvalue>      
      <description><![CDATA[Set the html onchange attribute on rendered html element]]></description>      
    </attribute>      
    <attribute>      
      <name>onclick</name>      
      <required>false</required>      
      <rtexprvalue>false</rtexprvalue>      
      <description><![CDATA[Set the html onclick attribute on rendered html element]]></description>      
    </attribute>      
    <attribute>      
      <name>ondblclick</name>      
      <required>false</required>      
      <rtexprvalue>false</rtexprvalue>      
      <description><![CDATA[Set the html ondblclick attribute on rendered html element]]></description>      
    </attribute>      
    <attribute>      
      <name>onfocus</name>      
      <required>false</required>      
      <rtexprvalue>false</rtexprvalue>      
      <description><![CDATA[Set the html onfocus attribute on rendered html element]]></description>      
    </attribute>      
    <attribute>      
      <name>onkeydown</name>      
      <required>false</required>      
      <rtexprvalue>false</rtexprvalue>      
      <description><![CDATA[Set the html onkeydown attribute on rendered html element]]></description>      
    </attribute>      
    <attribute>      
      <name>onkeypress</name>      
      <required>false</required>      
      <rtexprvalue>false</rtexprvalue>      
      <description><![CDATA[Set the html onkeypress attribute on rendered html element]]></description>      
    </attribute>      
    <attribute>      
      <name>onkeyup</name>      
      <required>false</required>      
      <rtexprvalue>false</rtexprvalue>      
      <description><![CDATA[Set the html onkeyup attribute on rendered html element]]></description>      
    </attribute>      
    <attribute>      
      <name>onmousedown</name>      
      <required>false</required>      
      <rtexprvalue>false</rtexprvalue>      
      <description><![CDATA[Set the html onmousedown attribute on rendered html element]]></description>      
    </attribute>      
    <attribute>      
      <name>onmousemove</name>      
      <required>false</required>      
      <rtexprvalue>false</rtexprvalue>      
      <description><![CDATA[Set the html onmousemove attribute on rendered html element]]></description>      
    </attribute>      
    <attribute>      
      <name>onmouseout</name>      
      <required>false</required>      
      <rtexprvalue>false</rtexprvalue>      
      <description><![CDATA[Set the html onmouseout attribute on rendered html element]]></description>      
    </attribute>      
    <attribute>      
      <name>onmouseover</name>      
      <required>false</required>      
      <rtexprvalue>false</rtexprvalue>      
      <description><![CDATA[Set the html onmouseover attribute on rendered html element]]></description>      
    </attribute>      
    <attribute>      
      <name>onmouseup</name>      
      <required>false</required>      
      <rtexprvalue>false</rtexprvalue>      
      <description><![CDATA[Set the html onmouseup attribute on rendered html element]]></description>      
    </attribute>      
    <attribute>      
      <name>onselect</name>      
      <required>false</required>      
      <rtexprvalue>false</rtexprvalue>      
      <description><![CDATA[Set the html onselect attribute on rendered html element]]></description>      
    </attribute>      
    <attribute>      
      <name>required</name>      
      <required>false</required>      
      <rtexprvalue>false</rtexprvalue>      
      <description><![CDATA[If set to true, the rendered element will indicate that input is required]]></description>      
    </attribute>      
    <attribute>      
      <name>requiredposition</name>      
      <required>false</required>      
      <rtexprvalue>false</rtexprvalue>      
      <description><![CDATA[Define required position of required form element (left|right)]]></description>      
    </attribute>      
    <attribute>      
      <name>tabindex</name>      
      <required>false</required>      
      <rtexprvalue>false</rtexprvalue>      
      <description><![CDATA[Set the html tabindex attribute on rendered html element]]></description>      
    </attribute>      
    <attribute>      
      <name>template</name>      
      <required>false</required>      
      <rtexprvalue>false</rtexprvalue>      
      <description><![CDATA[The template (other than default) to use for rendering the element]]></description>      
    </attribute>      
    <attribute>      
      <name>templateDir</name>      
      <required>false</required>      
      <rtexprvalue>false</rtexprvalue>      
      <description><![CDATA[The template directory.]]></description>      
    </attribute>      
    <attribute>      
      <name>theme</name>      
      <required>false</required>      
      <rtexprvalue>false</rtexprvalue>      
      <description><![CDATA[The theme (other than default) to use for rendering the element]]></description>      
    </attribute>      
    <attribute>      
      <name>title</name>      
      <required>false</required>      
      <rtexprvalue>false</rtexprvalue>      
      <description><![CDATA[Set the html title attribute on rendered html element]]></description>      
    </attribute>      
    <attribute>      
      <name>tooltip</name>      
      <required>false</required>      
      <rtexprvalue>false</rtexprvalue>      
      <description><![CDATA[Set the tooltip of this particular component]]></description>      
    </attribute>      
    <attribute>      
      <name>tooltipConfig</name>      
      <required>false</required>      
      <rtexprvalue>false</rtexprvalue>      
      <description><![CDATA[Set the tooltip configuration]]></description>      
    </attribute>      
    <attribute>      
      <name>value</name>      
      <required>false</required>      
      <rtexprvalue>false</rtexprvalue>      
      <description><![CDATA[Preset the value of input element.]]></description>      
    </attribute>      
    </tag>      
           
    <tag>      
    <name>textfield</name>      
    <tag-class>org.apache.struts2.views.jsp.ui.TextFieldTag</tag-class>      
    <body-content>JSP</body-content>      
    <description><![CDATA[Render an HTML input field of type text]]></description>      
           
  </tag>      
</taglib> 

原UIBean通用的属性我是直接从struts2源代码包里面copy来的.支持属性非常丰富.呵呵

建立组件类和标签类:

Pager.java:



/***********************************************************************     
*     
*   Pager.java     
*     
*   @creator       Bruce Tsai  
*   @create-time   Jun 12, 2009   10:53:38 PM     
***********************************************************************/  
  
package org.icim.pager.struts2;   
  
import org.apache.struts2.components.UIBean;   
import org.apache.struts2.views.annotations.StrutsTag;   
import org.apache.struts2.views.annotations.StrutsTagAttribute;   
import com.opensymphony.xwork2.util.ValueStack;   
  
import javax.servlet.http.HttpServletRequest;   
import javax.servlet.http.HttpServletResponse;   
  
/**  
* struts2版的分页标签  
*   
*/  
  
@StrutsTag(name = "pager", tldTagClass = "org.icim.pager.struts2.PagerTag", description = "struts2 pager by ithink")   
public class Pager extends UIBean {   
  
    final public static String TEMPLATE = "pager";   
  
    protected String totalRecord;   
    protected String totalPage;   
    protected String curPage;   
    protected String pageLimit;   
    protected String url;   
    protected String curCssClass;   
    protected String showTotalPage;   
    protected String showTotalRecord;   
    protected String directJumpType;   
  
    public Pager(ValueStack stack, HttpServletRequest request,   
            HttpServletResponse response) {   
        super(stack, request, response);   
    }   
  
    /**  
     * 用于返回模板的名字,Struts2会自动在后面加入.ftl扩展名以找到特定的模板文件。  
     */  
    @Override  
    protected String getDefaultTemplate() {   
        return TEMPLATE;   
    }   
  
    /**  
     * 设置UIBean的属性,一般Tag中有几个这样的属性,这里就有几个 StrutsTagAttribute注解,说明该属性是int类型,这一步很重要  
     *   
     * @param totalPage  
     */  
  
    @StrutsTagAttribute(description = "total records", type = "Long")   
    public void setTotalRecord(String totalRecord) {   
        this.totalRecord = totalRecord;   
    }   
  
    @StrutsTagAttribute(description = "total pages", type = "Integer")   
    public void setTotalPage(String totalPage) {   
        this.totalPage = totalPage;   
    }   
  
    @StrutsTagAttribute(description = "current page", type = "Integer")   
    public void setCurPage(String curPage) {   
        this.curPage = curPage;   
    }   
  
    @StrutsTagAttribute(description = "how many pages in a panel once", type = "Integer")   
    public void setPageLimit(String pageLimit) {   
        this.pageLimit = pageLimit;   
    }   
  
    @StrutsTagAttribute(description = "url to be linked", type = "String")   
    public void setUrl(String url) {   
        this.url = url;   
    }   
  
    @StrutsTagAttribute(description = "css style of current page", type = "String")   
    public void setCurCssClass(String curCssClass) {   
        this.curCssClass = curCssClass;   
    }   
  
    @StrutsTagAttribute(description = "whether to show totalPage", type = "Boolean", defaultValue = "true")   
    public void setShowTotalPage(String showTotalPage) {   
        this.showTotalPage = showTotalPage;   
    }   
  
    @StrutsTagAttribute(description = "whether to show currentPage", type = "Boolean", defaultValue = "false")   
    public void setShowTotalRecord(String showTotalRecord) {   
        this.showTotalRecord = showTotalRecord;   
    }   
  
    // TODO 直接页面跳转   
    // 这里的directJumpType默认值为none, 可选值为 'select', 'goto'   
    @StrutsTagAttribute(description = "show type of direct jump type. such as select,textbox which can lead going to a page directly", type = "String", defaultValue = "none")   
    public void setDirectJumpType(String directJumpType) {   
        this.directJumpType = directJumpType;   
    }   
  
    /**  
     * 重写evaluateExtraParams()方法,在UIBean初始化后会调用这个方法来初始化设定参数,如addParameter方法,会在freemarker里的parameters里加入一个key  
     * value。这里要注意findString,还有相关的findxxxx方法,它们是已经封装好了的解释ognl语法的工具,具体是怎么样的,大家可以查看一下UIBean的api  
     * doc  
     */  
    @Override  
    protected void evaluateExtraParams() {   
        super.evaluateExtraParams();   
        // findValue()方法本身已对OGNL进行了处理   
  
        if (totalRecord != null) {   
            addParameter("totalRecord", findValue(totalRecord));   
        }   
  
        if (totalPage != null) {   
            addParameter("totalPage", findValue(totalPage));   
        }   
  
        if (curPage != null) {   
            addParameter("curPage", findValue(curPage));   
        }   
  
        if (pageLimit != null) {   
            addParameter("pageLimit", findValue(pageLimit));   
        }   
  
        if (url != null) {   
            addParameter("url", findValue(url, String.class));   
        }   
  
        if (curCssClass != null) {   
            addParameter("curCssClass", findValue(curCssClass,String.class));   
        }   
  
        if (showTotalPage != null) {   
            addParameter("showTotalPage", findValue(showTotalPage,   
                    Boolean.class));   
        }   
  
        if (showTotalRecord != null) {   
            addParameter("showTotalRecord", findValue(showTotalRecord,Boolean.class));   
        }   
  
        if (directJumpType != null) {   
            addParameter("directJumpType", findValue(directJumpType));   
        }   
  
    }   
}   PagerTag.java:

/***********************************************************************     
*     
*   PagerTag.java     
*     
*   @creator       Bruce Tsai  
*   @create-time   Jun 13, 2009   12:08:53 AM     
***********************************************************************/  
  
package org.icim.pager.struts2;   
  
import org.apache.struts2.views.jsp.ui.AbstractUITag;   
import org.apache.struts2.components.Component;   
import com.opensymphony.xwork2.util.ValueStack;   
  
import javax.servlet.http.HttpServletRequest;   
import javax.servlet.http.HttpServletResponse;   
  
/**  
* struts2 版分页标签  
*/  
public class PagerTag extends AbstractUITag {   
       
    private static final long serialVersionUID = 719669934024053141L;   
       
    protected String totalRecord;   
    protected String totalPage;   
    protected String curPage;   
    protected String pageLimit;   
    protected String url;   
    protected String curCssClass;   
    protected String showTotalPage;   
    protected String showTotalRecord;   
    protected String directJumpType;   
  
    protected void populateParams() {   
  
        super.populateParams();   
  
        Pager pager = (Pager) component;   
           
        pager.setTotalRecord(totalRecord);   
        pager.setTotalPage(totalPage);   
        pager.setCurPage(curPage);   
        pager.setPageLimit(pageLimit);   
        pager.setUrl(url);   
        pager.setCurCssClass(curCssClass);   
        pager.setShowTotalPage(showTotalPage);   
        pager.setShowTotalRecord(showTotalRecord);   
        pager.setDirectJumpType(directJumpType);   
  
    }   
  
    @Override  
    public Component getBean(ValueStack stack, HttpServletRequest request,   
            HttpServletResponse response) {   
        return new Pager(stack, request, response);   
    }   
  
    public void setTotalRecord(String totalRecord){   
        this.totalRecord = totalRecord;   
    }   
       
    public void setTotalPage(String totalPage) {   
        this.totalPage = totalPage;   
    }   
  
    public void setCurPage(String curPage) {   
        this.curPage = curPage;   
    }   
  
    public void setPageLimit(String pageLimit) {   
        this.pageLimit = pageLimit;   
    }   
  
    public void setUrl(String url) {   
        this.url = url;   
    }   
  
    public void setCurCssClass(String curCssClass) {   
        this.curCssClass = curCssClass;   
    }   
  
    public void setShowTotalPage(String showTotalPage) {   
        this.showTotalPage = showTotalPage;   
    }   
  
    public void setShowTotalRecord(String showTotalRecord) {   
        this.showTotalRecord = showTotalRecord;   
    }   
  
    public void setDirectJumpType(String directJumpType) {   
        this.directJumpType = directJumpType;   
    }   
       
       


在类文件根目录下(在myeclipse中是在src目录下,发布后会copy到web-inf/classes/ 里)建立template/simple/ 目录,里面创建pager.ftl文件,内容如下:



<#--显示总记录数,只有同时设置了总记录数和显示总记录数时才有效-->  
<#if (parameters.totalRecord?exists) && (parameters.showTotalRecord?exists) && (parameters.showTotalRecord == true)>  
    <span>${parameters.totalRecord}</span><#rt/>  
</#if>  
  
<#--打印选择页的面板 -->  
<#--首先,当parameters.pageLimit为空时将其设定为total-->  
<#if (parameters.pageLimit?exists)>  
    <#assign limit = parameters.pageLimit />  
<#else>  
    <#assign limit = parameters.totalPage />  
</#if>  
<@pagePanel cur=parameters.curPage total=parameters.totalPage url=parameters.url limitlimit=limit />  
<#--打印选择页的面板结束-->  
  
<#--显示总页数-->  
<#if parameters.showTotalPage?exists && (parameters.showTotalPage == true)>  
    <span>..${parameters.totalPage}</span><#rt/>  
</#if>  
  
<#--打印翻页面板的宏,配合printPage,printButton-->  
<#macro pagePanel cur total limit url curCssClass = "cur_page"><#--curCssClass默认值为cur_page-->  
    <#--limit的中间数-->  
    <#assign l_mid = (limit/2)?int + 1 />  
       
    <#--total的中间数-->  
    <#assign t_mid = (total/2)?int />  
       
    <#--情况一:总页数小于等于限制显示页数,这时显示所有页-->  
    <#if total <= limit>  
        <@printButton direct="left" valuable = false />  
        <@printPage left = 1 right = total curcur = cur urlurl = url curCssClasscurCssClass = curCssClass />  
        <@printButton direct="right" valuable = false />                   
    <#else>  
    <#--情况二:总页数大于限制显示页数,这时又分三种情况-->  
        <#--情况1:显示的limit个页号在total个页面中偏向左端,1作为最左边的页号,当前页没能显示在中间,偏左,例:   
            total = 20,cur = 2,limit = 5.显示的页面为:1 [2] 3 4 5   
            这种情况 cur <= l_mid    
        -->  
        <#if cur <= l_mid>  
            <@printButton direct="left" valuable = false />  
            <@printPage left = 1 right = limit curcur = cur urlurl = url curCssClasscurCssClass = curCssClass />  
            <@printButton direct="right" valuable = true />  
               
        <#--情况2:显示的limit个页号在total个页面中偏向右端,total作为最右边的页号,当前页没能显示在中间,偏右,例:   
            total = 20,cur = 19,limit = 5.显示的页面为:16 17 18 [19] 20   
            这种情况 cur > total - l_mid   
        -->  
        <#elseif (cur > (total - l_mid))>  
            <@printButton direct="left" valuable = true />  
            <@printPage left = (total - limit + 1) right = total curcur = cur urlurl = url curCssClasscurCssClass = curCssClass />  
            <@printButton direct="right" valuable = false />  
               
        <#--在中间的情况-->  
        <#else>  
            <@printButton direct="left" valuable = true />  
            <@printPage left = (cur - l_mid + 1) right = (cur + l_mid -1) curcur = cur urlurl = url curCssClasscurCssClass = curCssClass />  
            <@printButton direct="right" valuable = true />  
        </#if>  
    </#if>  
       
</#macro>  
  
<#--根据最左与最右的页号来打印所显示的页面,当前页为的cssStyle为curCssClass-->  
<#macro printPage left right cur url curCssClass>  
    <#list left..right as p>  
        <#if p == cur>  
            <span class = "${curCssClass}" >${p}</span><#rt/>  
        <#else>  
            <a href = "<@makeURL text=url page=p />">${p}</a><#rt/>  
        </#if>         
    </#list>       
</#macro>  
  
<#--翻页控制按钮,direct选择"left"或"right",avaluable设置是否有链接-->  
<#macro printButton direct valuable = true>  
    <#if direct == "left">  
        <#if valuable>  
            <a href="<@makeURL text=parameters.url page=1 />"> << </a><#rt/>  
            <a href="<@makeURL text=parameters.url page=parameters.curPage-1 />"> < </a><#rt/>  
        <#else>  
            <span><<</span><#rt/>  
            <span><</span><#rt/>  
        </#if>  
    <#else>  
        <#if valuable>  
            <a href="<@makeURL text=parameters.url page=parameters.curPage+1 />"> > </a><#rt/>  
            <a href="<@makeURL text=parameters.url page=parameters.totalPage />"> >> </a><#rt/>  
        <#else>  
            <span>></span><#rt/>  
            <span>>></span><#rt/>  
        </#if>  
    </#if>  
</#macro>  
  
<#--产生动态URL的宏-->  
<#macro makeURL text page>  
    <#if text?last_index_of("{page}") < 0>  
        ${text}?page=${page}   
    <#else>  
        ${text?replace("{page}",page)}   
    </#if>     
</#macro> 

最后,需要在你的struts.xml配置文件里做如下设置


<constant name="struts.ui.theme" value="simple" />  

也就是对应之前建立的theme/simple目录



这样标签部分就做完了.下面使用标签.建立test.jsp



<%@ page language="java" contentType="text/html; charset=utf-8"  
    pageEncoding="utf-8"%>  
<%@ taglib prefix="s" uri="/struts-tags"%>  
<%@ taglib prefix="ithink" uri="/ithink-tags"%>  
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">  
<html>  
    <head>  
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">  
        <title>pager tag test</title>  
    </head>  
    <body>  
        <div class="pagination">  
            <ithink:pager curPage="3" totalPage="88"  
                url="listPaper.action?pno={page}" pageLimit="9" showTotalPage="true"  
                totalRecord="1988" showTotalRecord="true" />  
        </div>  
    </body>  
</html>  




还需要为它设置CSS样式:

/*---------------------pagination-----------------------------*/  
  
div.pagination {   
    padding:5px;   
    margin:5px;   
    text-align:center;   
    float:left;   
    font-size:12px;   
}   
  
div.pagination a {   
    padding: 2px 5px 2px 5px;   
    margin-right: 2px;   
    border: 1px solid #ddd;   
    text-decoration: none;    
    color: #d8325d;   
}   
div.pagination a:hover, div.pagination a:active {   
    border:1px solid #ddd;   
    color: #fff;   
    background-color: #d8325d;   
}   
div.pagination span.cur_page {   
    padding: 2px 5px 2px 5px;   
    margin-right: 2px;   
    border: 1px solid #ddd;   
    font-weight: bold;   
    background-color: #d8325d;   
    color: #FFF;   
}   
div.pagination span {   
    padding: 2px 5px 2px 5px;   
    margin-right: 2px;   
    border: 1px solid #ddd;   
    text-decoration: none;    
    color: #d8325d;   
}  
到此一切都OVER了.如果你觉得我的实现不能满足要求,完全可以自己再写一个pager.ftl.只要在使用标签时指定theme属性,比如说"text",然后再在theme/text目录下重新写一个pager.ftl就行了
分享到:
评论
1 楼 學會☆~Snow 2010-06-06  
有点乱。。。。。

相关推荐

    用struts分页标签

    下面我们将详细探讨如何利用Struts分页标签来实现高效的页面导航。 首先,我们需要理解分页的基本原理。分页是将大量数据分成若干个小部分,每次只加载一部分数据到页面上,以提高用户体验和网页加载速度。在Struts...

    Struts2自定义分页标签

    本资源详细介绍了如何在Struts2中自定义分页标签,使得开发过程更加便捷。 在Struts2中,分页通常涉及到以下几个关键步骤: 1. **创建Action类**:首先,你需要创建一个Action类,该类将处理用户的请求,包括获取...

    struts分页标签

    Struts分页标签是Java Web开发中的一种常见技术,主要用于在网页上展示大量数据时进行分页处理,提高用户体验。Struts是一个基于MVC(Model-View-Controller)设计模式的开源框架,它使得Java Web应用程序的开发变得...

    基于struts2 自定义标签 分页

    在这个基于Struts2的自定义分页标签的实践中,我们将深入探讨如何创建、配置和使用自定义标签来实现数据的分页展示,同时与Oracle数据库进行交互。 首先,理解分页的基本概念至关重要。分页是将大量数据分成小块,...

    struts2做的分页标签

    本文将详细介绍如何在Struts2中实现分页标签,并提供一个简洁易懂的项目示例。 1. **Struts2分页概念**: 分页是将大量数据分割成若干小块,每次只加载一部分数据到页面上,使得用户可以逐页浏览,减轻服务器压力...

    Struts分页.Struts分页.

    总的来说,Struts分页的优势在于其模块化的设计,通过ActionForm、Action、标签库和拦截器等组件,能够将分页逻辑从业务逻辑中解耦,使代码更易于维护和扩展。同时,其提供的各种功能,如国际化、主题支持和性能优化...

    jsp +struts 分页经典

    本项目名为“jsp +struts 分页经典”,显然是一个利用这两种技术实现的分页展示数据的案例。下面我们将深入探讨JSP和Struts框架,以及它们在分页、查询和数据操作中的应用。 首先,JSP是Java平台上的动态网页技术,...

    struts自制标签分页封装

    在分页标签中,我们需要考虑参数如当前页、总页数、每页显示条数等。 3. **模型驱动**:在 Struts 框架中,可以使用模型驱动的方式来处理分页。模型对象包含了关于数据分页的信息,如总记录数、当前页数等。通过...

    Struts2分页-自定义标签-类似百度分页

    通过对`TagDemo`的分析和学习,你可以更好地理解和应用Struts2自定义标签实现分页功能。 总之,Struts2自定义标签提供了一种灵活的方式,使得开发者能够在JSP页面中方便地实现分页效果。通过自定义标签,我们可以将...

    java web中的struts分页组件

    本代码示例专注于Struts中如何实现分页功能。 首先,我们需要了解分页的基本概念。分页是将大量数据分为多个较小的、易于管理的部分,每次只加载一部分数据到客户端。这通常通过两个主要部分实现:前端(用户界面)...

    struts分页,数据查询资料

    DisplayTag是一个强大的表格和分页标签库,它提供了一系列预定义的标签,可以轻松地在JSP页面上实现分页和排序功能。在Action类中,你需要计算总页数,并将当前页、总页数、每页记录数等信息放入ActionContext,然后...

    一个高效简洁的Struts分页方法

    下面将详细解释如何在一个高效简洁的方式下实现Struts分页。 首先,我们需要理解分页的基本原理。分页通常是通过在数据库中限制查询结果的数量,每次只加载一定数量的数据(称为一页),然后根据用户的交互(如点击...

    分页大全(含JDBC分页 struts分页)

    这里我们将深入探讨“分页大全”,包括JDBC分页、Struts分页以及分页标签的使用。 首先,让我们了解什么是分页。在网页或应用中,分页是指将大量数据分割成若干小部分,每次只加载一部分,用户可以逐页浏览,而不是...

    Struts完整分页

    通过以上步骤,我们可以构建出一个完整的Struts分页系统。这个过程中,关键是理解Struts的MVC架构以及如何在各层之间传递和处理分页信息。熟练掌握分页技术不仅能够提升用户体验,也有助于优化应用的性能和可维护性...

    Struts+Hibernate分页标签

    在处理大量数据时,为了提高用户体验,通常会采用分页显示数据,这就是所谓的"Struts+Hibernate分页标签"。在这个场景下,我们将深入探讨如何在Struts2框架中使用自定义标签来实现与Hibernate的整合,完成数据的分页...

    自定义struts2 分页标签

    本教程将详细介绍如何在Struts2中自定义分页标签。 在传统的网页开发中,分页通常通过服务器端脚本或JavaScript实现,但在Struts2框架中,我们可以创建自定义标签来完成这一任务,使得代码更加模块化和易于维护。...

    自定义标签代替Struts标签实现分页

    在Java Web开发中,Struts框架是常用的MVC框架之一...这种方式比直接使用Struts的分页标签更加灵活,但需要更多的编码工作。总的来说,自定义标签是Java Web开发中的一个重要技能,能够提升应用的可维护性和可扩展性。

Global site tag (gtag.js) - Google Analytics