標籤: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 檔案