import javax.servlet.jsp.tagext.TagSupport; import javax.servlet.jsp.JspWriter; /** * Created by IntelliJ IDEA. * User: qiao * Date: 2008-1-29 * Time: 10:19:40 * To change this template use File | Settings | File Templates. */ public class SearchPageTag extends TagSupport { private int iPageSize = 20; private int iRecordTotal = 0; private String sSubmitFile = ""; private int iCurrPage = 1; private String sSubmitForm = ""; public int iStart = 0;//每一頁起始記錄號 public int iMax = 0;//每一頁結束記錄號 private int iPageCount = 0;//頁數 public void setsSubmitForm(String sSubmitForm) { this.sSubmitForm = sSubmitForm; } public void setiPageSize(int iPageSize) { this.iPageSize = iPageSize; } public void setiRecordTotal(int iRecordTotal) { this.iRecordTotal = iRecordTotal; } public void setsSubmitFile(String sSubmitFile) { this.sSubmitFile = sSubmitFile; } public void setiCurrPage(int iCurrPage) { this.iCurrPage = iCurrPage; } /** * 設置分頁大小 * */ public void setPage() { //計算總頁數 if(iRecordTotal % iPageSize >0) { iPageCount = iRecordTotal / iPageSize + 1; } else { iPageCount = iRecordTotal / iPageSize; } if (iPageCount > 0) {//有檢索結果 if (iCurrPage <= 0) {//頁碼爲負時 iCurrPage = 1; } if (iCurrPage > iPageCount) {//頁碼大於總頁數時 iCurrPage = iPageCount; } } if (iCurrPage > 1) { //當前頁不爲1時的起始記錄號 iStart = (iCurrPage - 1) * iPageSize; } else { //起始記錄號 iStart = 0; } //最大記錄號 iMax = iCurrPage * iPageSize; if(iMax > iRecordTotal) { iMax = iRecordTotal; } } public int doStartTag() { setPage(); try { String sUrl = " "; if (iCurrPage == 1) //第一頁 { if (iPageCount == 1 || iPageCount == 0) {//只有一頁 sUrl = "[首頁] [上一頁] [下一頁] [尾頁] "; } else { sUrl = "[首頁] [上一頁] <a href='#'onclick='" + sSubmitForm + ".action=/"" + sSubmitFile + "?currPage=" + (iCurrPage + 1) + "/";" + sSubmitForm + ".submit();'>[下一頁]</a> <a href='#'onclick='" + sSubmitForm + ".action=/"" + sSubmitFile + "?currPage=" + iPageCount + "/";" + sSubmitForm + ".submit();'>[尾頁]</a>"; } } else { if (iCurrPage == iPageCount) //最後一頁 { sUrl = "<a href='#'onclick='" + sSubmitForm + ".action=/"" + sSubmitFile + "?currPage=1/";" + sSubmitForm + ".submit();'>[首頁]</a> <a href='#' onclick='" + sSubmitForm + ".action=/"" + sSubmitFile + "?currPage=" + (iCurrPage - 1) + "/";" + sSubmitForm + ".submit();'>[上一頁]</a> [下一頁] [尾頁]"; } else //不是第一頁與最後一頁 { sUrl = "<a href='#'onclick='" + sSubmitForm + ".action=/"" + sSubmitFile + "?currPage=1/";" + sSubmitForm + ".submit();'>[首頁]</a> <a href='#'onclick='" + sSubmitForm + ".action=/"" + sSubmitFile + "?currPage=" + (iCurrPage - 1) + "/";" + sSubmitForm + ".submit();'>[上一頁]</a> <a href='#'onclick='" + sSubmitForm + ".action=/"" + sSubmitFile + "?currPage=" + (iCurrPage + 1) + "/";" + sSubmitForm + ".submit();'>[下一頁]</a> <a href='#'onclick='" + sSubmitForm + ".action=/"" + sSubmitFile + "?currPage=" + iPageCount + "/";" + sSubmitForm + ".submit();'>[尾頁]</a> "; } } if (iPageCount <= 0) { iCurrPage = 0; //sUrl+=" 當前第<span align=right class='orangebold'>" + iCurrPage + "/" + iPageCount + "</span>頁 直接跳轉到第 <input name='currPage' id='currPage' value=/"" + iCurrPage + "/" type='text' size='3'> 頁 <img src='../images/button_go.gif' width='25' height='25'onclick='" + sFormName + ".action=/"" + sSubmitFile + "/";" + sFormName + ".submit(); '>"; } else { if (iCurrPage <= 0) { iCurrPage = 1; } if (iCurrPage > iPageCount) { iCurrPage = iPageCount; } //sUrl+=" 當前第<span align=right class='orangebold'>" + iCurrPage + "/" + iPageCount + "</span>頁 直接跳轉到第 <input name='currPage' id='currPage' value=/"" + iCurrPage + "/" type='text' size='3'> 頁 <img src='../images/button_go.gif' width='25' height='25'onclick='" + sFormName + ".action=/"" + sSubmitFile + "/";" + sFormName + ".submit(); '>"; } sUrl += " 當前第<span align=right class='orangebold'>" + iCurrPage + "/" + iPageCount + "</span>頁 直接跳轉到第 <input name='currPage' id='currPage' value=/"" + iCurrPage + "/" type='text' size='3'> 頁 <img src='images/button_go.gif' width='25' height='25'onclick='" + sSubmitForm + ".action=/"" + sSubmitFile + "/";" + sSubmitForm + ".submit(); '>"; JspWriter out = pageContext.getOut(); out.print(sUrl); } catch (Exception ex) { System.out.print("error"); } return (SKIP_BODY); } } |
類分頁
日誌 > 技術交流
評論列表
溫馨提示:點擊驗證碼輸入框,以獲取驗證碼
請輸入驗證碼:
loading......
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.