我已经制作了tld和tag holder(Body Tag Support类型),其中src
是必需属性。
在JSP中:
<%@taglib uri="/WEB-INF/tlds/tld1.tld" prefix="imageViewer1"%>
<!DOCTYPE html>
<html>
<body>
<imageViewer1:NewTagHandler src="dd"></imageViewer1:NewTagHandler>
</body>
</html>
在标记处理程序中,我只打印src
。但我没有输出。
在tld1.tld:
<tag>
<name>NewTagHandler</name>
<tag-class>taghandler.NewTagHandler</tag-class>
<body-content>JSP</body-content>
<attribute>
<name>src</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
<type>java.lang.String</type>
</attribute>
</tag>
在taghandler.NewTagHandler
中@Override
public int doAfterBody() throws JspException {
try {
BodyContent bodyCont = getBodyContent();
JspWriter out = bodyCont.getEnclosingWriter();
out.println(src);
writeTagBodyContent(out, bodyCont);
} catch (Exception ex) {
handleBodyContentException(ex);
}
if (theBodyShouldBeEvaluatedAgain()) {
return EVAL_BODY_AGAIN;
} else {
return SKIP_BODY;
}
}