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"%>
标签:function,searchString,Java,String,extend,text,JSTL,lastIndexOf
From: https://blog.51cto.com/u_16070335/6189746