首先在WEB配置页面中添加tld文件
其次,然后再WEB.XML文件中配置说明
<!-- 添加自定义JSP标签 --> <jsp-config> <!-- 在JSP页面中同样也需要引用标签,这里只是获取的uri定义结果不一样 --> <taglib> <taglib-uri>/hb</taglib-uri> <taglib-location>/WEB-INF/taglibs/c.tld</taglib-location> </taglib> <taglib> <taglib-uri>/fmt</taglib-uri> <taglib-location>/WEB-INF/taglibs/fmt.tld</taglib-location> </taglib> <taglib> <taglib-uri>/functions</taglib-uri> <taglib-location>/WEB-INF/taglibs/fn.tld</taglib-location> </taglib> </jsp-config>
最后,页面展示
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <%@ taglib prefix="c" uri="/hb"%> <%@ taglib prefix="fmt" uri="/fmt"%> <%@ taglib prefix="fn" uri="/functions"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>My JSP 'fn.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> </head> <body> 使用fn功能是对集合长度的取值<p></p> <% ArrayList arrayList1 = new ArrayList(); arrayList1.add("aa"); arrayList1.add("bb"); arrayList1.add("cc"); request.getSession().setAttribute("arrayList1",arrayList1); %> ${fn:length(sessionScope.arrayList1) } <hr/> fn:contains函数用来判断源字符串是否包含子字符串<br/> ${fn:contains("ABC","a") }<br/> ${fn:contains("ABC","A") } <hr/> fn:containsIgnoreCase跟fn:contains函数差不多,唯一的区别是不区分大小写 <br/> ${fn:containsIgnoreCase("ABC","a") }<br/> ${fn:containsIgnoreCase("ABC","A") } <hr/> fn:startsWith函数用来判断源字符串是否符合一连串的特定词头(区分大小写)<br/> ${fn:startsWith("ABC","ab") }<br/> ${fn:startsWith("ABC","AB") } <hr/> fn:endsWith函数用来判断源字符串是否符合一连串特定词尾(区分大小写)<br> ${fn:endsWith("ABC","bc") }<br/> ${fn:endsWith("ABC","BC") } <hr/> fn:indexOf函数用于取得子字符串与源字符串匹配的开始位置,如果没有匹配的将返回-1<br/> ${fn:indexOf("ABCD","BC") }<br/> ${fn:indexOf("ABCD","aBC") } <hr/> fn:join函数允许为一个字符串数组中的每个字符串加上分隔符连接起来<br> <% String[] stringArray={"huang","biao","dage"}; request.setAttribute("stringArray",stringArray); %> ${stringArray }<br/> ${fn:join(stringArray,"-") } <hr/> fn:replace函数允许为源字符串做替换工作<br/> ${fn:replace("ABC","A","#") } <hr/> fn:split函数用于将一组由分隔符分隔的字符串转换为字符串数组<br/> ${fn:split("a,b,c",",") } <hr/> fn:trim函数将删除源字符串中结尾部分的“空格”以产生新的字符串<br/> ${fn:trim("abc ") }d<br> <hr/> fn:toUpperCase函数允许将源字符串中的字符全部转换为大写字母<br> ${fn:toUpperCase("abcd") } <hr/> fn:toLowerCase函数允许将源字符串中的字符全部转换成小写字母<br/> ${fn:toLowerCase("ABCD") } <HR/> fn:substringBefore函数允许截取源字符串从开始到某个字符串<br/> ${fn:substringBefore("ABCD","BC") } <hr/> fn:substringAfter函数允许截取源字符串结尾的后一个字符<br/> ${fn:substringAfter("ABCD","BC") } <hr/> fn:substring函数用于截取字符串<br/> ${fn:substring("ABC",1,2) } <hr/> </body> </html>
备注:上面的配置信息不是必须的,只是为了学习使用