EL expression User-Defined Function, el Expression Function

Source: Internet
Author: User

EL expression User-Defined Function, el Expression Function

In addition to basic operators, the expression language can also use user-defined functions. The function of Expression Language is enhanced by using custom functions.

EL expression functions are mainly used to modify data and unify the format;

Procedure

1. Develop a function processing class. The processing class is a common class. Each function corresponds to a static method in the class;

2. Create a TLD file and define expression functions;

3. import and use the JSP page;

1. Development function processing class

package com.itnba.maya.zidingyi;public class Zidingyi {    public static String zhuanhuan(String txt){        txt=txt.replaceAll("&", "&amp;").replaceAll("\"", "&quot;").replaceAll("<", "&lt;").replaceAll(">", "&gt;");        txt=txt.replaceAll("/n", "</p><p>");        txt="<p>"+txt+"</p>";        return txt;    }}

2. Create a configuration TLD File

Created in the WEB-INF folder

Configuration

<? 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> UDF </description> <display-name> my el function </display-name> <tlib- version> 1.0 </tlib-version> <short-name> fn </short-name> <uri> http://www.itnba.com </uri> <function> <description> display text content change to the display content of the webpage </description> <name> zhuanhuan </name> <function-class> com. itnba. maya. zidingyi. zidingyi </function-class> <function-signature> String zhuanhuan (java. lang. string) </function-signature> <example>... </example> </function> </taglib>

3. import and use

<% @ Page language = "java" contentType = "text/html; charset = ISO-8859-1 "pageEncoding =" ISO-8859-1 "%> <% @ taglib prefix =" my "uri =" http://www.itnba.com "%> <% -- call -- %> <! DOCTYPE html PUBLIC "-// W3C // dtd html 4.01 Transitional // EN" "http://www.w3.org/TR/html4/loose.dtd"> 

Display result

 

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.