Use of JSP El udfs

Source: Internet
Author: User
Tags tld

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.


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.