欧美三区_成人在线免费观看视频_欧美极品少妇xxxxⅹ免费视频_a级毛片免费播放_鲁一鲁中文字幕久久_亚洲一级特黄

struts 分頁標簽

系統 1922 0
實現自定義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就行了

struts 分頁標簽


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 欧美视频二区 | 蜜臀AV在线观看 | 国产苐1页影院草草影院 | 任我爽在线视频 | 一区二区三区视频 | 特黄a级片 | jjzzjjzz在线观看| 亚洲精品久久久中文字幕 | 人人干视频在线观看 | jiucao视频在线观看 | 国产永久免费 | 亚洲一区二区三区在线 | 欧美一级视频 | 性夜影院爽黄a免费视频 | 亚洲激情一区 | 最新中文字幕日本 | 一本大道香蕉中文日本不卡高清二区 | 男女猛烈激情xx00免费视频 | 一级黄色淫片 | 激情视频在线观看网站 | 日本 欧美 国产 | 天天色综合天天 | 天天综合久久 | 毛片链接 | 精品亚洲国产成av人片传媒 | 色呦呦在线看 | 久久成年人视频 | 蜜桃精品久久久久久久免费影院 | 欧美日韩一区二区三区自拍 | 日韩男人的天堂 | 日本在线免费观看视频 | 人阁色第四影院在线电影 | 日韩在线免费 | 日韩免费大片 | 久久精品道一区二区三区 | 污视频在线免费播放 | 日韩免费看 | 国产成人福利 | 久久久成 | 国产在线综合网 | 国产熟妇无码A片AAA毛片视频 |