//ListAllBodyTagExtraInfo.java
public class ListAllBodyTagExtraInfo extends TagExtraInfo {
public ListAllBodyTagExtraInfo() { }
/**
* 让JSP引擎确定参数类型
*/
public VariableInfo[] getVariableInfo(TagData data) {
return new VariableInfo[] {
/**
* 参数名,类型,是否声明新变量,范围
* 范围取值:AT_BEGIN,AT_END,NESTED(标记有效范围内)
*/
new VariableInfo("name", "java.lang.String", true, VariableInfo.NESTED) ,
new VariableInfo("value", "java.lang.Integer", true, VariableInfo.NESTED),
};
}
}
定义该函数后,声明正确的tld,可以这么使用
<definetag attr1="value">
<%=name%>is <%=value%>
</definetag>
VariableInfo
public VariableInfo(java.lang.String varName,
java.lang.String className,
boolean declare,
int scope)
-
Constructor These objects can be created (at translation time) by the TagExtraInfo instances.
-
参数:
-
varName- The name of the scripting variable -
className- The type of this variable -
declare- If true, it is a new variable (in some languages this will require a declaration) -
scope- Indication on the lexical scope of the variable
-
字段摘要
static intAT_BEGIN
Scope information that scripting variable is visible after start tag.
static intAT_END
Scope information that scripting variable is visible after end tag.
static intNESTED
Scope information that scripting variable is visible only within the start/end tags.![]()
![]()
JSP TagExtraInfo 使用详解
本文详细介绍了如何通过自定义 Java 类 `ListAllBodyTagExtraInfo` 实现 JSP 标签属性的动态类型确定。通过重写 `getVariableInfo` 方法,可以指定标签参数的类型、作用域等信息,使开发者能够更灵活地使用自定义标签。
2552

被折叠的 条评论
为什么被折叠?



