Resolve custom El function Eclipse report the function is undefined error

Source: Internet
Author: User
Tags tld

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.