Java_JSTL_extend function tags

来源:互联网 发布:sql删除一个月前数据 编辑:程序博客网 时间:2024/05/21 17:57

1.create the function class

package cn.com.benyoyo.manage.core.common.tools;

public class ElExFuncs {

public static int lastIndexOf(String text, String searchString) {

if (text == null) text = "";

if (searchString == null) searchString = "";

return text.lastIndexOf(searchString);

}

}

 

2. create tld file

<?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>A extend JSTL 1.1 functions library for cmis</description>

  <display-name>JSTL extend functions</display-name>

  <tlib-version>1.1</tlib-version>

  <short-name>fn-ex</short-name>

  <function>

    <description>Returns the index withing a string of the last occurrence of a specified substring.</description>

    <name>lastIndexOf</name>

    <function-class>cn.com.benyoyo.manage.core.common.tools.ElExFuncs</function-class>

    <function-signature>int lastIndexOf(java.lang.String, java.lang.String)</function-signature>

    <example>

      ${fn:lastIndexOf(name, "-")}

    </example>

  </function>

</taglib>

 

3.import taglib in jsp

<%@ taglib prefix="fnex" uri="/WEB-INF/config/tld/fn-ex.tld"%>

0 0
原创粉丝点击