• 自定义jsp标签


    1.类:

    package ===============================;
    
    import javax.servlet.jsp.JspTagException;
    import javax.servlet.jsp.tagext.BodyTagSupport;
    
    public class DCAclTag extends BodyTagSupport {
    
        private static final long serialVersionUID = 1L;
    
        /**
         * 传入进来的值,权限判断需要的条见
         */
        private int control;
        private int permission;
    
        public int getControl() {
            return control;
        }
    
        public void setControl(int control) {
            this.control = control;
        }
    
        public int getPermission() {
            return permission;
        }
    
        public void setPermission(int permission) {
            this.permission = permission;
        }
    
        /**
         * doStartTag方法,如果value为true,那么 就计算tagbody的值,否则不计算body的值。
         */
        public int doStartTag() throws JspTagException {
            if (PermissionUtil.checkPermission(permission, control)) {
                return EVAL_BODY_INCLUDE;
            } else {
                return SKIP_BODY;
            }
        }
    
        /**
         * 覆盖doEndTag方法
         */
        public int doEndTag() throws JspTagException {
            try {
                if (bodyContent != null) {
                    bodyContent.writeOut(bodyContent.getEnclosingWriter());
                }
            } catch (java.io.IOException e) {
                throw new JspTagException("IO Error: " + e.getMessage());
            }
            return EVAL_PAGE;
        }
    
    }

    在WEB-INF下的配置文件dc.tdl

    <?xml version="1.0" encoding="ISO-8859-1" ?>
    <taglib xmlns="http://java.sun.com/xml/ns/j2ee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee web-jsptaglibrary_2_0.xsd"
        version="2.0">
        <description>A tag library exercising SimpleTag handlers.</description>
        <tlib-version>1.0</tlib-version>
     
          <short-name>dctag</short-name>
          <uri>http://www.dc.com/tags</uri>
          <description>
            dctag
          </description>
     
        <tag>
           <name>acl</name>
           <tag-class>com.dc.platform.ss.permission.DCAclTag</tag-class>
           <body-content>jsp</body-content>
           <attribute>
                 <name>control</name>
                 <required>true</required>
                 <rtexprvalue>true</rtexprvalue>
           </attribute>
           <attribute>
                 <name>permission</name>
                 <required>true</required>
                 <rtexprvalue>true</rtexprvalue>
           </attribute>
       </tag>
    </taglib>

    web.xml下的配置:

        <taglib>
            <taglib-uri>http://www.dc.com/tags</taglib-uri>
            <taglib-location>/WEB-INF/dc.tld</taglib-location>
        </taglib>

    页面调用: 引入改自定义标签

    <%@ taglib prefix="dc" uri="http://www.dc.com/tags" %>
    
    <dc:acl permission="<%=11%>" control="<%=aclState %>">    
        <li><a class="edit" href="s?md=${module.sn}&ac=turnNotice&rowId={rowid}" target="dialog" width="500" height="220" title="确定要转入公告吗?"><span>转入公告</span></a></li>
        <li class="line">line</li>
    </dc:acl>
  • 相关阅读:
    Ubuntu 虚拟机空间不足增加空间笔记
    am335x sd卡启动开启识别emmc kernel 上的改动
    Delphi实现树型结构具体实例
    学习 TTreeView [15]
    delphi中Treeview的使用介绍
    按下F2编辑dxDBTreeView的节点
    dbtreeview
    我的dbtreeview–treeview直接连接数据表_delphi教程
    SqlDbx连接oracle(可用)
    SqlDbx连接oracle(无需安装Oracle客户端)
  • 原文地址:https://www.cnblogs.com/clovem/p/5919134.html
Copyright © 2020-2023  润新知