• JSP 中的 tag 文件


    在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 标签?

    实际运行结果:与注释没有任何关系……

  • 相关阅读:
    常用、好用的资源管理器收藏
    单片机延时函数整理——针对裸机
    ad7793的调试记录
    《80c51单片机实用技术》邹久朋学习笔记
    使用串口工具(volt++ vofa)伏特加来实时打印波形
    golang从简单的即时聊天来看架构演变
    无敌简单快速的文件服务器sgfs
    到底是否应该使用“微服务架构”?
    你所学习的设计模式到底有什么用?到底怎么用?
    浅入深出ETCD之【raft原理】
  • 原文地址:https://www.cnblogs.com/panie2015/p/6121159.html
Copyright © 2020-2023  润新知