When you write a small project, you encounter the need to turn a long string into small dots, and immediately think of defining a custom function
Package cn.harmel.common.util;/** * Tool class for manipulating strings * * @author Harmel * */public Final class StringUtils {private Stringut Ils () {} public static string transform (string str, int length) {if (Str.length () > Length) { Return str.substring (0, length) + "..."; } return str; }}
As a rule, you need to define a TLD file in any directory under/web-inf (except tags), which I define in/web-inf/tag
<?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>harmel ' s tag</description> <tlib-version>1.0</tlib-version> <short-name>h</short-name> <uri>http://www.harmel.cn/tag</uri> <function> <name>subStr</name> <function-class>cn.harmel.common.util.stringutils</ function-class> <function-signature>java.lang.string transform (Java.lang.String, int) </function-signature> </function> </ Taglib>
When you're done, import the tags in the JSP page immediately.
<%@ taglib prefix= "h" uri= "Http://www.harmel.cn/tag"%>${h:substr ("123456789012345", 10)}
The test passed the function to the other pages, modified the file eclipse immediately after the build workspace found in the/web-inf JSP page has a big Red fork, and its/web-inf outside the JSP page is not. Hint that the function h:substr is undefined but the deployment runs without problems. Now that the Tomcat container has been able to automatically search for the TLD under the/web-inf, consider that Eclipse is not smart enough to solve obsessive-compulsive disorder, the tag definition is given in Web. xml:
<jsp-config> <taglib> <taglib-uri>http://www.harmel.cn/tag</taglib-uri> <tagli B-location>/web-inf/tag/harmel.tld</taglib-location> </taglib></jsp-config>
Succeeded in solving the obsessive-compulsive disorder.
Resolve custom El function Eclipse report the function is undefined error