几个阶段:
前doStartTag()
中 doAfterBody()
后doEndTag()
优点:有各种处理阶段对应的方法,可以在这些阶段的方法中,增加自定义方法。
方式2:函数式(一个标签对应一个方法)
1,新建处理方法
a) 这个方法所在类可以是任意pojo类
b) 这个方法是public static 返回类型 方法名称(任意参数)
c) 有返回的直接返回,不用考虑放入上下文
2,新增描述
在tld文件中增加类似以下描述即可
<function>
<name>hkName</name>
<function-class>test.org.nutz.taglib.TestFounction</function-class>
<function-signature>java.lang.String getName(java.lang.String)</function-signature>
</function>
3,页面使用
EL表达式格式
${imsp:**** }
注意:这里遇到一个问题,上面的代码复制过会,总是包The function xxx cannot be located with the specified prefix
最后的解决是因为将原有的function代码复制就好了,所以估计是空格导致编译后的function格式不能解析。
1、The function xxx must be used with a prefix when a default namespace is not specified
--- 在jsp页面中调用方式不正确,可能将 ":" 写成了 "."
2、The function xxx cannot be located with the specified prefix
--- a) 类中定义的方法不是 public static 的方法
b) 类中的方法名称和jsp自带的标签元素冲突,重名等
优点:简单灵活。但没有状态,在jsp页面执行到时触发调用,完成后回到jsp
修改tld文件,是可以不重启直接使用的 。