<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    jsp標簽

        剛剛結束了一個項目,有點時間,所以先補充補充自己的知識,昨天學了一下Jsp標簽,感覺挺好的,可以使jsp頁面干凈不少,維護起來更方便了。
        下邊就開始進入正題:
    首先創建一個Pagination.tld文件,標簽文件:
    <?xml   version="1.0"   encoding="UTF-8"?>
      <taglib>
          <tlibversion>1.0</tlibversion>
          <jspversion>1.1</jspversion>  
          <shortname>Pagination</shortname>  
          <tag>
          <name>Pagination</name>
          <tagclass>tags.Pagination</tagclass> 
          <attribute>
              <name>allpage</name>
              <required>true</required>
              <rtexprvalue>true</rtexprvalue>
          </attribute>
          <attribute>
              <name>currentpage</name>
              <required>true</required>
              <rtexprvalue>true</rtexprvalue>
          </attribute>
          <attribute>
              <name>action</name>
              <required>true</required>
              <rtexprvalue>true</rtexprvalue>
          </attribute>
          <attribute>
              <name>allcount</name>
              <required>true</required>
              <rtexprvalue>true</rtexprvalue>
          </attribute>
          </tag>
    </taglib>

    tlibversion: 標簽庫版本
    jspversion: 標簽庫依賴的jsp版本
    shortname:  標簽庫名
    tag          開始一個標簽
    name         標簽名
    tagclass     指定標簽處理程序類
    attribute    開始一個標簽屬性,可用于傳入參數
    name         屬性名
    required和rtexprvalue都是屬性的設置,均有2個屬性ture和false用來決定是否必須指定

    接下來創建該標簽的處理程序類Pagination.java:

    package tags;   
    import java.util.*;
    import javax.servlet.jsp.JspException;     
    import javax.servlet.jsp.tagext.TagSupport;         
    public class Pagination extends TagSupport {
        private String allpage; //總頁數
        private String currentpage; //當前頁數
        private String action; //form請求地址
        private String allcount; //總記錄數
        public int doStartTag() throws JspException {     
            try {
                StringBuffer cont = new StringBuffer();
                String context = "<form action='"+action+"'>" +
                    "<table><tr><td colspan='7' align='right'>" +
                    "<a>總頁數:"+allpage+"</a>&nbsp" +
                    "<a>總記錄數:"+allcount+"</a>&nbsp";
                    if(Integer.valueOf(currentpage)>2){
                        context = context + "<a href='"+action+"?num=1'>第一

    頁</a>&nbsp";
                    }
                   
                    if(Integer.valueOf(currentpage)>1){
                        context = context + "<a href='"+action+"?num="+

    (Integer.valueOf(currentpage)-1)+"'>前一頁</a>&nbsp";
                    }
                   
                        context = context + "<a >當前

    頁:"+currentpage+"</a>&nbsp";
                       
                    if(Integer.valueOf(currentpage)<Integer.valueOf(allpage)){
                        context = context + "<a href='"+action+"?num="+

    (Integer.valueOf(currentpage)+1)+"'>下一頁</a>&nbsp";
                    }
                   
                    if(Integer.valueOf(currentpage)<(Integer.valueOf(allpage)-

    1)){
                        context = context + "<a href='"+action+"?

    num="+allpage+"'>最后一頁</a>&nbsp";
                    }
                   
                    context = context + "</td><td align='center' width='15%'>" +
                                        "<input type='text'

    size='1' name='num' id='pagenum' value=''  />" +
                                        "<input

    type='submit' value='GO' id='gobutton'></td></tr></table>";
                   
                pageContext.getOut().print(context);
            }catch(Exception e) {
                throw new JspException("SimpleTag:"+e.getMessage());     
            }
            return EVAL_BODY_INCLUDE;         
        }     
        public int doEndTag() {     
            return EVAL_PAGE;     
        }
        public void setAllpage(String allpage) {
            this.allpage = allpage;
        }
        public void setCurrentpage(String currentpage) {
            this.currentpage = currentpage;
        }
        public void setAction(String action) {
            this.action = action;
        }
        public void setAllcount(String allcount) {
            this.allcount = allcount;
        }
    }

    最后是要顯示的Jsp頁index.jsp:
      <%@ page language="java" pageEncoding="utf-8"%>
      <%@ taglib uri="/WEB-INF/tags/Pagination.tld" prefix="Pagination" %>
      <html>
      <head>
          <script type="text/javascript" src="js/Time.js"></script>
      </head>
      <body>
          <Pagination:Pagination allcount="20" action="servlet" currentpage="1" allpage="200"></Pagination:Pagination>
      </body>
      </html>

    posted on 2007-10-30 14:34 dripstone 閱讀(322) 評論(0)  編輯  收藏


    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    <2007年10月>
    30123456
    78910111213
    14151617181920
    21222324252627
    28293031123
    45678910

    導航

    統計

    常用鏈接

    留言簿(1)

    隨筆分類(1)

    隨筆檔案(16)

    友情鏈接

    搜索

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 亚洲精品国产福利一二区| 在线播放高清国语自产拍免费| 免费a级毛片无码av| 亚洲综合激情五月丁香六月| 国产成人精品免费视频大| 久久亚洲私人国产精品| 69av免费观看| 亚洲国产高清在线精品一区| 又黄又爽又成人免费视频| 2020年亚洲天天爽天天噜| 成人毛片免费在线观看| 亚洲伊人久久大香线蕉AV| 国产又黄又爽又猛的免费视频播放| 亚洲AV无码一区二区三区网址| 亚洲国产精品无码中文字| sihu国产精品永久免费| 中文亚洲AV片不卡在线观看| 久久成人无码国产免费播放| 中文字幕亚洲第一在线| 免费观看黄网站在线播放| 色九月亚洲综合网| 国产亚洲欧洲Aⅴ综合一区 | 久久亚洲国产最新网站| 国产精品视_精品国产免费| 日韩精品无码永久免费网站| 综合亚洲伊人午夜网| 暖暖日本免费中文字幕| 亚洲三级视频在线| 免费看一级做a爰片久久| 免费毛片在线看不用播放器| 亚洲综合婷婷久久| 精品国产麻豆免费网站| 免费无码又爽又刺激网站| 亚洲大片免费观看| 亚洲AV无码专区日韩| 日韩视频免费在线观看| 亚洲国产熟亚洲女视频| 亚洲综合色在线观看亚洲| 天天影视色香欲综合免费| 99亚洲乱人伦aⅴ精品| 亚洲成人免费在线|