篇十七:tag文件的使用

1、tag概述css

  JSP標籤有兩種實現方法,一種是使用tag 文件,一種是使用tld文件。java

  tag文件的使用:標籤名和tag文件名一致, tag文件爲JSP文件,能夠有屬性jsp

2、tag使用ui

  一、tag文件的定義 pager_backstage.tagspa

  知識點解析:code

    a、定義屬性--屬性attribute,有變量名(name),是否必需(required),屬性類型(type),至關於定義一個JavaBean的屬性。在使用屬性的值時,可經過get方法來訪問或經過變量名的方式來訪問;orm

      屬性設爲必需後,在引用的地方,設置參數同樣使用  blog

<%@ tag pageEncoding="UTF-8" %>
<%@ include file="/WEB-INF/jsp/common/global.jsp" %>

<%@ attribute name="id" required="true" type="java.lang.String" %>
<%@ attribute name="pager" required="true" type="com.guduo.common.page.PageBean" %>

<c:set var="currentPage" value="${pager.currentPage}"/>
<c:set var="numPerPage" value="${pager.numPerPage}"/>
<c:set var="totalRecord" value="${pager.totalCount}"/>
<c:set var="totalPage" value="${pager.pageCount}"/>

<div class="pager-css-row">
    <div class="css-right">
        <div id="${id}">
            <span>頁面編號:</span>
            <span class="ext-pager-pn">${currentPage}</span>
            <span>/</span>
            <span class="ext-pager-tp">${totalPage}</span>
            <span class="css-blank-10"></span>
            <span>每頁條數:</span>
            <select class="ext-pager-ps" style="width:45px; height:30px; font-size: 14px; font-weight: normal; color: #333333; background-color: #ffffff; border: 1px solid #e5e5e5;">
                <option value="10" <c:if test="${numPerPage=='10'}">selected="selected" </c:if>>10</option>
                <option value="15" <c:if test="${numPerPage=='15'}">selected="selected" </c:if>>15</option>
                <option value="20" <c:if test="${numPerPage=='20'}">selected="selected" </c:if>>20</option>
            </select>
            <span class="css-blank-10"></span>
            <span>總記錄數:</span>
            <span>${totalRecord}</span>
            <span class="css-blank-10"></span>
            <div class="css-button-group ext-pager-button">
                <c:choose>
                    <c:when test="${currentPage > 1 && currentPage <= totalPage}">
                        <button type="button" title="第一頁" class="btnEnabled" data-pn="1">|&lt;</button>
                        <button type="button" title="上頁" class="btnEnabled" data-pn="${currentPage - 1}">&lt;</button>
                    </c:when>
                    <c:otherwise>
                        <button type="button" title="第一頁" class="btnDisabled" disabled>|&lt;</button>
                        <button type="button" title="上頁" class="btnDisabled" disabled>&lt;</button>
                    </c:otherwise>
                </c:choose>
                <c:choose>
                    <c:when test="${currentPage < totalPage}">
                        <button type="button" title="下頁" class="btnEnabled" data-pn="${currentPage + 1}">&gt;</button>
                        <button type="button" title="最後一頁" class="btnEnabled" data-pn="${totalPage}">&gt;|</button>
                    </c:when>
                    <c:otherwise>
                        <button type="button" title="下頁" class="btnDisabled" disabled>&gt;</button>
                        <button type="button" title="最後一頁" class="btnDisabled" disabled>&gt;|</button>
                    </c:otherwise>
                </c:choose>
            </div>
        </div>
    </div>
</div>

  二、使用tagget

//一、在界面引入 tag文件
<%@ taglib prefix="tag" tagdir="/WEB-INF/tags" %>

//二、使用
<tag:pager_backstage id="list_page" pager="${page}"/>
相關文章
相關標籤/搜索