tag文件与tag标记,java自定义标签

在目录:’Web服务器\WEB-INF\tags‘ 下创建存放xxx.tag的tag文件

demo:

    jsp页面:

 

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!--
使用<taglib>指令标记引入该Web服务目录下的标记库,只有这样,JSP页面才可以使用Tag标记调用相应的Tag文件。<taglib>指令的格式如下:
    <%@ taglib tagdir="自定义标记库的位置" prefix="前缀"> 
-->
<%@taglib tagdir="/WEB-INF/tags" prefix="beijing" %>
<%@taglib tagdir="/WEB-INF/tags/geng" prefix="dalian" %>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body bgcolor="cyan">
        <h3>以下是调用Tag文件的效果:</h3>
        <beijing:AddSum />
        <h3>以下是调用Tag文件的效果:</h3>
        <dalian:EvenSum />
    </body>
</html>

 tag文件

 

 

<%@ tag language="java" pageEncoding="UTF-8"%>
<p>这是一个Tag文件,负责计算1~100内的奇数之和:</p>
<%   int sum=0, i=1;
     for(i=1;i<=100;i++)
     {  if(i%2==1)
        sum=sum+i;
     }
	 out.println(sum); 
%>

 

<%@ tag language="java" pageEncoding="UTF-8"%>
<p>这是一个Tag文件,负责计算1~100内的偶数之和:</p>
<%  int sum=0;
	int i=1;
    for(i=1;i<=100;i++){  
    	if(i%2==0){
	       sum=sum+i;
    	}
    }	
    out.println(sum); 
%>

 

<body bgcolor="yellow"><p>
    <%
       int size=1;
       for(int i=1;i<=3;i++)
        {
           size=size+1;          
    %>
        <font size="<%=size %>">
             <!--一下的代码表示页面的文字将传入进来-->
             <jsp:doBody />
         </font>
       <% }%>
       <p>
</body>

 较复杂的tag文件,仅供参考:

 

 

<%@ tag import="com.mip.core.util.MipConfig"%>
<%@ tag language="java" pageEncoding="UTF-8"%>
<%@tag import="com.mip.core.security.objects.Loginer,com.mip.core.basebiz.view.web.controller.control.grid.vo.JqgridParam,java.util.List,java.util.Map,java.util.HashMap,java.util.Map.Entry,com.mip.common.dictionary.service.impl.DictionaryServiceImpl,com.mip.core.basebiz.dto.DataRecord"%>

<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="mip" tagdir="/WEB-INF/tags" %>
<%-- 必填字段 --%>
<%@ attribute name="divId" required="true"%>
<%@ attribute name="colName" fragment="true" description="在mip:column中定义"%>
<%@ attribute name="cols" fragment="true" description="在mip:column中定义"%>
<%@ attribute name="url" description="表格列表数据请求URL地址" required="true"%>

<%-- 可选字段 --%>
<%@ attribute name="sortname"  description="表格排序的列"%>
<%@ attribute name="idColumn" description="主键字段名称"%>
<%@ attribute name="pager" description="表格底部页脚id,如果为空,没有页脚,没有翻页"%>
<%@ attribute name="pagerWithContent" description="表格底部通用查询、刷新、收缩/展开搜索栏是否带文字,
默认为false不带,true的时候追加文字"%>

<%@ attribute name="caption" description="表格的名字"%>
<%@ attribute name="rowNum" description="默认为20 整型数字"%>
<%@ attribute name="sortorder" description="排序方式"%>
<%@ attribute name="filterToolbar" description="顶部搜索栏true|false"%>
<%@ attribute name="filterToolbarSearchType" description="顶部搜索栏搜索类型,默认为bw(以XX开头),
	可选值:eq,ne,bw,bn,cn,nc,ew,en,nu,nn 对应的意思:'相等','不等', 
	'开始于', '不开始于','like %%','not like %%', '结束于','不结束于','为空','不为空'] "%>
<%@ attribute name="toggleFilterToolbar" description="在底部增加隐藏/显示顶部搜索栏的按钮"%>
<%@ attribute name="edit" description="是否显示编辑按钮 true|false"%>
<%@ attribute name="add" description="是否显示新增按钮 true|false"%>
<%@ attribute name="del" description="是否显示删除按钮 true|false"%>
<%@ attribute name="editurl" description="增删改存储地址url"%>
<%@ attribute name="initEdit" description="进入表格之后就初始化列为可编辑状态,默认为false,为true时生效"%>

<%@ attribute name="rownumbers" description="是否显示行数 true|false"%>
<%@ attribute name="width" description="表格宽度   
	此字段废弃,所有表格都会取自己父容器的宽度,如果要设置该表格的宽度,使用div或其他标签抱住表格,然后设置父容器的宽度"%>
<%@ attribute name="autowidth" description="是否自动调整宽度为父级的宽度true|false,
	此字段废弃,所有继承系统模板的jsp页面中的表格都会自适应宽度为父容器的宽度"%>
<%@ attribute name="noautowidth" description="是否自动调整宽度为父级的宽度true|false,
	此字段废弃,所有继承系统模板的jsp页面中的表格都会自适应宽度为父容器的宽度"%>
<%@ attribute name="height" description="表格高度"%>
<%@ attribute name="multiselect" description="多选框"%>
<%@ attribute name="multiboxonly" description="默认为true只有选择checkbox时才选中此行,设置false时点击记录时就会选中此行"%>
<%@ attribute name="singleselect" description="单选框"%>
<%@ attribute name="gridComplete" description="表格完成之后的回调"%>
<%@ attribute name="onSelectRow" description="选择某行之后触发的事件,方法声明原型onCellSelect(rowid,status)"%>
<%@ attribute name="onCellSelect" description="点击单元格触发的实际,
	要把edit属性设置为false,否则不起作用.方法声明原型onCellSelect(rowid,iCol,cellcontent,event)"%>
<%@ attribute name="autoComplete" description="true|false 为true时打开列搜索的自动匹配    已废弃"%>
<%@ attribute name="tableName" description="自动匹配的表名称,在头部搜索栏的自动设值中会用到"%>
<%@ attribute name="rownumbersClick" description="序号点击时触发的js函数名字,调用时会传递当前行的rowid"%>
<%@ attribute name="shrinkToFit" description="自动调整表格的列宽度适应表格整体宽度,默认为true,
自动调整后的宽度为:(列当前设置宽度/所有列设置的宽度 )*表格的宽度
当表格列较多时设置为false时使用列自己指定的宽度数值,此参数主要针对列较多的情况"%>

<%@ attribute name="isKeepParam" description="是否在返回时保持表格参数 ,默认为保存,"%>

<!-- 分组参数 -->
<%@ attribute name="grouping" description="分组显示 true|false 默认false 分组显示时不会自动生成序号"%>
<%@ attribute name="groupField" description="分组列的Field名字,多个用,隔开,分组显示时的必填项"%>
<%@ attribute name="groupColumnShow" description="是否显示分组的列 true|false,默认是false,多个使用,隔开"%>
<%@ attribute name="groupText" description="显示的分组标题格式"%>
<%@ attribute name="groupCollapse" description="默认是否展开,默认是true"%>
<%@ attribute name="groupOrder" description="分组显示 排序方式  asc|desc 默认desc"%>

<!-- 树参数 -->
<%@ attribute name="treeGrid"  description="是否包含树节点"%>
<%@ attribute name="expandColClick" description="是否点击时打开"%>
<%@ attribute name="expandColumn" description="父节点列名称"%>
<%@ attribute name="jqOption" description="自定义jqgrid对象"%>
<%@ attribute name="setFrozenColumns" description="是否冻结表头,默认为false, bug如果设置了单选,多选冻结表头都会不正常,跟他的实现机制有关,如果单元格出现换行表头会无法对其"%>

<%@ attribute name="userDataOnFooter" description="汇总"%>
<%@ attribute name="footerrow" description="汇总"%>
<%@ attribute name="gridview" description="加快表格解析速度,默认为true,注意,如果使用treeGrid, subGrid and afterInsertRow (event)那么需要把gridview设为false"%>

<c:if test="${empty pagerWithContent}">
<c:set var="pagerWithContent" value="true" /><%-- 设置默认值 --%>
</c:if>

 

 

 

 

 

 

Tag文件中经常使用的指令有:

               tag、taglib、include、attribute、variable

Tag指令的语法如下:

              <%@  tag 属性1="属性值" 属性2="属性值"  … 属性n="属性值" %>

Tag指令可以操作的属性有:

              body-content、language、import、pageEncoding。

 

 

例如:

<%@ tag import="com.mip.core.util.MipConfig"%>

<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>

<%@ attribute name="colName" fragment="true" description="在mip:column中定义"%>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值