编写EL函数

xiaoxiao2021-02-28  91

一般来说,创建一个EL函数要遵循两个步骤 1.创建一个包含静态方法的public类 2.利用function元素在tld里面注册函数

静态方法的类:

public class EL { public static String reverseString(String s){ return new StringBuffer(s).reverse().toString(); } }

注册:

<?xml version="1.0" encoding="ISO-8859-1"?> <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" verson="2.0"> <description>Function tag example</description> <tlib-version>1.0</tlib-version> <jspversion>2.3</jspversion> <function> <description>Reverse a String</description> <name>reverseString</name> <function-class>tag.EL</function-class> <function-signature> java.lang.String reverseString(java.lang.String) </function-signature> </function> </taglib>

使用:

结果:

转载请注明原文地址: https://www.6miu.com/read-77027.html

最新回复(0)