jsp調用java方法 function taglib


1、新建tld文件:

my-functions.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">
    <description>functions</description>
    <tlib-version>3.0</tlib-version>
    <short-name>fn</short-name>
    <uri>http://mysteel.com/shiro/tags/mysteel-functions</uri>


    <function>
        <description>根據船code顯示船名稱</description>
        <name>shipName</name>
        <function-class>com.test.system.web.taglib.Functions</function-class>
        <function-signature>java.lang.String getShipName(java.lang.String)</function-signature>
    </function>


</taglib>

2、建立java類:

package com.test.system.web.taglib;


import com.portx.util.XmlReaderUtil;
import org.springframework.util.CollectionUtils;


import java.util.Collection;


public class Functions {

    public static String getShipName(String code) {

        return XmlReaderUtil.getValueByKey(code);
    }

}

 

3、在web.xml中定義:

<jsp-config>
        <taglib>
            <taglib-uri>/tags</taglib-uri>
            <taglib-location>/WEB-INF/tld/datetag.tld</taglib-location>
        </taglib>
        <taglib>
            <taglib-uri>/functions</taglib-uri>
            <taglib-location>/WEB-INF/tld/mysteel-functions.tld</taglib-location>
        </taglib>
    </jsp-config>

 

4、jsp中調用

<%@ taglib prefix="fnc" uri="/functions" %>


${fnc:shipName(item.shipCorpCd)}

 

即可調用。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM