关于网友提出的“ JSTL中如何实现LastIndexOf”问题疑问,本网通过在网上对“ JSTL中如何实现LastIndexOf”有关的相关答案进行了整理,供用户进行参考,详细问题解答如下:
问题: JSTL中如何实现LastIndexOf
描述: 如题,我看了一些帮助文档都貌似JSTL标签中不包含这个方法,有什么办法去实现它么?
请大家指教一下,谢谢
解决方案1: 自己定义一个就可以了:
1. 定义一个类:
package functions;
public class Functions {
public Functions() {}
public static int lastIndexOf(String text, String searchString) {
return text.lastIndexOf(searchString);
}
}
2. 定义一个functions.tld:
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee web-jsptaglibrary_2_0.xsd"
version="2.0">
A tag library that defines a function.
1.0
FunctionTagLibrary
/FunctionLibrary
lastIndexOf
functions.Functions
int lastIndexOf(java.lang.String, java.lang.String)
3. 在jsp里用这个function:
<%@ taglib uri="/WEB-INF/functions.tld" prefix="f" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
以上介绍了“ JSTL中如何实现LastIndexOf”的问题解答,希望对有需要的网友有所帮助。
本文网址链接:http://www.codes51.com/itwd/3167199.html