you can see an interesting application, Turn it off, huh, huh !!
1. definition class myfunction ( note: method must be Public static)
Package Com. tgb. jstl;
/**
* UDF implementation class in the jstl label
*
*/
Public Class Myfunctions {
Public Static String sayhello (string name ){
Return "Hello" + name;
}
}
2.ProvideTLDDescription file,This file can be placed inWEB-INFOr under its Directory.
<? 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 > Myfunctions Library </ Description >
< Display-name > Jstl Functions </ Display-name >
< Tlib-version > 1.1 </ Tlib-version >
<! -- The so-called "abbreviation" here can be written at will -->
< Short-name > MFN </ Short-name >
<! -- The URI here can be written at will -->
< Uri > Http://www.tgb.com/functions </ Uri >
< Function >
<! -- The name can be written as needed. -->
< Name > Say </ Name >
<! -- It is most important to specify the class location and some important information about the class method. -->
< Function-class > Com. tgb. jstl. myfunctions </ Function-class >
< Function-Signature > Java. Lang. String sayhello (Java. Lang. String) </ Function-Signature >
</ Function >
</ Taglib >
3.InJSPUseTaglibIntroduce function library
< % @ Taglib Uri = Http://www.tgb.com/functions" Prefix = "MFN" % >
4. in El + colon + use function names
call functions related to the function library, El Expression.
$ {MFN: say ("Tom")} <--- "Tom" can be changed to an El expression