Step 1: TLD Function Definition:
First, under the WEB-INF folder under the project folder, see a function-taglib.tld File
This file is actually an XML description file with the following content:
<? 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 web-jsptaglibrary_2_0.xsd"
Version = "2.0">
<Description> A taglib to define some el accessible functions. </description>
<Tlib-version> 1.0 </tlib-version>
<Short-Name> elfunctiontaglib </short-Name>
<URI> elfunctiontaglibrary </uri>
<Function>
<Description> exposes the ABS () function from Java. Lang. Math package </description>
<Name> ABS </Name>
<Function-class> JAVA. Lang. Math </function-class>
<Function-signature> int ABS (INT) </function-signature>
</Function>
</Taglib>
The aboveCodeMeaning:
Create an El function tag library,<URI> elfunctiontaglibrary </uri>Indicates the URI in the taglib of JSP <@ taglib prefix = ''EF"
Uri ="Elfunctiontaglibrary">
If you want to define El udfs: Use
<Function>
<Description> Add a description here </description>
<Name> function name </Name>
<Function-class> here is the class that implements the function </function-class>
<Function-signature> here is the function signature </function-signature>
</Function>
If you want to add other functions, add them to the TLD file in the above format.
Step 2: Use the El function:
The code for creating the test. jsp page is as follows:
<% @ Page Language = "Java" Import = "Java. util. *" pageencoding = "UTF-8" %>
<% @ Taglib prefix = "Ef" uri = "elfunctiontaglibrary" %>
<! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en">
<HTML>
<Head>
<Title> El function! </Title>
</Head>
<Body>
$ {EF: ABS (-7 )}
</Body>
</Html>
Note: The namespace of the ing function is EF, which has the following <taglib> command definition:
<% @ Taglib prefix = "Ef" uri = "elfunctiontaglibrary" %>,
The ABS () function is called by the following code in test. jsp:
$ {EF: ABS (-7 )}
Returns the absolute value of-7.