一个java文件:EL函数主要程序逻辑处理部分,要注意必须为公开静态的方法。
一个tld文件:EL函数、标签库的设定文件。
最后需要在web.xml中设定taglib的TLD文件位置。
tld文件的配置片段:
<function> <description> </description> <name> </name> <function-class> </function-class> <function-signature>java.lang.String test(java.lang.String)</function-signature> </function>
此外还需要tld文件的文件头。
web.xml中的配置片段:
<jsp-config> <taglib> <taglib-uri> http://localhost:8080/elfunctions </taglib-uri> <taglib-location> /WEB-INF/classes/META-INF/taglib.tld </taglib-location> </taglib> </jsp-config>
其中,<taglib-location>用来指定TLD 文件的位置
这一片段的意思为:taglib 的uri 为http://localhost:8080/elfunctions
,它的TLD 文件是/WEB-INF/classes/META-INF/下的taglib.tld文件。
在使用时需要加上:
<%@ taglib prefix=" " uri="http://localhost:8080/elfunctions" %>