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("&", "&").replaceAll("\"", """).replaceAll("<", "<").replaceAll(">", ">"); 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