码迷,mamicode.com
首页 > 编程语言 > 详细

jsp调用java方法 function taglib

时间:2016-05-27 16:28:41      阅读:142      评论:0      收藏:0      [点我收藏+]

标签:

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)}

 

即可调用。

 

jsp调用java方法 function taglib

标签:

原文地址:http://www.cnblogs.com/gmq-sh/p/5534743.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!