-
Write a tool class
public class Utilfunction {
Public Utilfunction () {
}
/**
* @param start 0,start intercept
* @param end end, intercept
* @param info
* @param t fill
* @return
*/
public static String subString (int start,int end,string info,string t) {
String infostart=info.substring (0,start);
String infoend=info.substring (end);
return infostart+t+infoend;
}
Test
public static void Main (string[] args) {
Mobile phone number before 3 4
System.out.println (Utilfunction.substring (3, 7, "15216888619", "* * * *"));
}
}
2. Define a. tld file below the Web-inf
<?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" >
<tlib-version>1.0</tlib-version>
<short-name>my</short-name>
<uri>http://www.xx.com</uri>
<!--jstl Custom function Get province--
<function>
<name>subString</name>
<function-class>util. Utilfunction</function-class>
<function-signature>java.util.string subString (int, int,java.lang.string,java.lang.string) </ Function-signature>
</function>
</taglib>
3.web.xml definition
<jsp-config>
<taglib>
<taglib-uri>http://www.xx.com</taglib-uri>
<taglib-location>/WEB-INF/tld/utilFunction.tld</taglib-location>
</taglib>
</jsp-config>
4.jsp page reference
<%@ taglib uri= "http://java.sun.com/jsp/jstl/functions" prefix= "FN"%>
<%@ taglib prefix= "YH" uri= "http://www.xx.com"%>
${xx:substring (3, 7, Userinfo.smobile, "* * *")}
Note:
UserInfo for Request.setbean ()
Request binding is ${userinfo.smobile} if the FN function uses remove ${}, direct userinfo.smobile
Custom Jstl function Label