zoukankan      html  css  js  c++  java
  • taglib 自定义标签

    自定义<%@ taglib prefix="cf" uri="http://training.bmcc.com.cn/tld/functions"%> 
    
    就可以根据${cf:proxyConfig('elearning_play')}

    实现自定义标签 读取  proxyConfig中的内容,

    如果我们使用jsp2,则web.xml使用的是servlet2.4以上的版本。那我们看一下web.xml对应的头文件:

    新增的特性是:

    <web-app version= "4" 
    xmlns="http://javasuncom/xml/ns/j2ee" 
    xmlns:xsi="http://wwwworg/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://javasuncom/xml/ns/j2ee 
    http://javasuncom/xml/ns/j2ee/web-app_2_xsd" > 
    </web-app> 

    首先在web.xml中添加如下代码:

     <jsp-config>
            <taglib>
                <taglib-uri>http://training.bmcc.com.cn/tld/functions</taglib-uri>
                <taglib-location>/WEB-INF/customfunction.tld</taglib-location>
            </taglib>
        </jsp-config>

    根据上面的

    <%@ taglib prefix="cf" uri="http://training.bmcc.com.cn/tld/functions"%> 

    得到taglib-location   这里得到的是customfunction.tld 找到如下文件:直接上代码

    <?xml version="1.0" encoding="UTF-8" ?>
    <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 http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"
        version="2.0">
        <display-name>Custom Functions</display-name>
        <tlib-version>1.1</tlib-version>
        <short-name>cf</short-name>
        <uri>http://training.bmcc.com.cn/tld/functions</uri>
        <function>
            <name>proxyConfig</name>
            <function-class>com.cmbj.training.common.util.ProxyConfigUtil</function-class>
            <function-signature>java.lang.String getProxyURL(java.lang.String)</function-signature>
        </function>
        <function>
            <name>popedomCheck</name>
            <function-class>com.cmbj.training.common.util.PopedomCheckUtil</function-class>
            <function-signature>boolean check(java.util.Map, java.lang.Integer)</function-signature>
        </function>
        <function>
            <name>checkEmployeeJob</name>
            <function-class>com.cmbj.training.common.util.UserJobUtil</function-class>
            <function-signature>boolean checkEmloyeeJob(java.lang.String)</function-signature>
        </function>
        <function>
            <name>checkManager</name>
            <function-class>com.cmbj.training.common.util.UserJobUtil</function-class>
            <function-signature>boolean checkManager(java.lang.String)</function-signature>
        </function>
        <function>
            <name>getValByKey</name>
            <function-class>com.cmbj.training.common.util.ConstantsMapUtil</function-class>
            <function-signature>java.lang.String getValByKey(java.util.Map, java.lang.String)</function-signature>
        </function>
        <function>
            <name>titleFormat</name>
            <function-class>common.base.util.StringUtil</function-class>
            <function-signature>java.lang.String titleFormat(java.lang.String, java.lang.Integer)</function-signature>
        </function>
        <function>
            <name>titleFormat2</name>
            <function-class>common.base.util.StringUtil</function-class>
            <function-signature>java.lang.String titleFormat(java.lang.String, java.lang.Integer, java.lang.String)</function-signature>
        </function>
    
        <function>
            <name>checkRoleByName</name>
            <function-class>com.bestnet.common.util.RoleUtil</function-class>
            <function-signature>boolean checkRoleByName(java.util.Map, java.lang.String)</function-signature>
        </function>
    
        <function>
            <name>checkRoleByCode</name>
            <function-class>com.bestnet.common.util.RoleUtil</function-class>
            <function-signature>boolean checkRoleByCode(java.util.Map, java.lang.String)</function-signature>
        </function>
    </taglib>

    根据name得到 类路径:

    <function-class>com.cmbj.training.common.util.ProxyConfigUtil</function-class>


    类内容如下:

    public class ProxyConfigUtil {
    
        private static ResourceLoadUtil RESOURCE_LOADUTIL = new ResourceLoadUtil("/proxyConfig.properties");
    
        private ProxyConfigUtil() {
    
        }
    
        public static String getProxyURL(String proxyURLKey, String defaultVal) {
            return RESOURCE_LOADUTIL.getVal(proxyURLKey, defaultVal);
        }
    
        public static String getProxyURL(String proxyURLKey) {
            return getProxyURL(proxyURLKey, "");
        }
        
        public static String getProxyParam(String key){
            return RESOURCE_LOADUTIL.getVal(key);
        }

    最后得到配置文件,读取内容,得到相应的url内容${cf:proxyConfig('elearning_play')}
    elearning_play=http://***.***.***:8011

    最终完成自定义标签的配置。


  • 相关阅读:
    小总结:fibonacci数的产生
    pick the stone game
    温故知新的错题训练:Coin game
    《博弈论的诡计》
    思维+博弈论:字符串操作
    一下午的编程思索录
    2018中国大学生程序设计竞赛
    温故知新的经典贪心题目:今年暑假不AC?
    2019-2020新学的一些东西(持续更新)
    【半平面交】JZOJ3297. 【SDOI2013】逃考
  • 原文地址:https://www.cnblogs.com/wupeng88/p/4520451.html
Copyright © 2011-2022 走看看