JSP 中的 tag 檔案

來源:互聯網
上載者:User

標籤:icon   des   not   程式   頁面   false   desc   ref   lan   

在jsp檔案中,可以引用 tag 和tld 檔案,本文主要針對 tag

 

對於tag 檔案

  1)將此類檔案放在 WEB-INF 下,比如 /WEB-INF/tags,tags 是目錄,其下可以有多個.tag檔案,如 tree.tag,menu.tag

  2)在jsp 中使用 <%@ taglib prefix="sys" tagdir="/WEB-INF/tags" %> 來引入

  3)在jsp 頁面上,採用<sys:xxx> 來使用該 tag 檔案,如 <sys:tree>、<sys:menu>

tag 檔案的作用一般是一段小代碼,類似 include 檔案的作用

 

例:

1、引入 tag 檔案

<%@ taglib prefix="sys" tagdir="/WEB-INF/tags/sys" %>

2、在  /WEB-INF/tags/sys 下,新增一個 test.tag 檔案

<%@ tag language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %><%@ attribute name="id" type="java.lang.String" required="true" description="編號"%><%@ attribute name="name" type="java.lang.String" required="true" description="輸入框名稱"%><%@ attribute name="value" type="java.lang.String" required="true" description="輸入框值"%><%@ attribute name="notAllowSelectParent" type="java.lang.Boolean" required="false" description="不允許選擇父節點"%><i id="${id}Icon" class="icon-${not empty value?value:‘ hide‘}"></i> <label id="${id}IconLabel">${not empty value?value:‘無‘}</label> <input id="${id}" name="${name}" type="hidden" value="${value}"/><a id="${id}Button" href="javascript:" class="btn">選擇</a>  <script type="text/javascript">$("#${id}Button").click(function(){//<c:if test="${notAllowSelectParent}">alert("不能選擇父節點");//</c:if>});</script>

3、在jsp 中使用該 tag

<sys:test name="test" value="test" id="test" notAllowSelectParent="true"></sys:test>

4、運行程式,可以發現程式正常運行

 

問題是:tag 中的 //<c:if test="${notAllowSelectParent}">  不是被注釋掉了嗎?為什麼還是能正常運行? 為什麼js 中可以使用 jstl 標籤?

實際運行結果:與注釋沒有任何關係……

 

JSP 中的 tag 檔案

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.