写了一个自定义标签类 想实现 在display为true的时候才显示标签体 package com.mybbs.jsptag;import javax.servlet.jsp.JspTagException;
import javax.servlet.jsp.tagext.BodyTagSupport;public class Status extends BodyTagSupport {
boolean display; public void setDisplay(boolean display) {
this.display = display;
}
public int doStarTag()
{
if(!display)
return SKIP_BODY;
else
return EVAL_BODY_BUFFERED;
}
public int DoEndTag() throws JspTagException
{
try
{
if(bodyContent!=null)
{
bodyContent.writeOut(bodyContent.getEnclosingWriter());
}
}
catch(java.io.IOException e)
{
throw new JspTagException("NO!");
}
return EVAL_PAGE;
}}
描述文件myTag.tld中的配置
<tag>
<name>status</name>
<tag-class>com.mybbs.jsptag.Status</tag-class>
<body-content>JSP</body-content>
<attribute>
<name>display</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>web.xml中的配置<jsp-config>
<taglib>
<taglib-uri>/MyTag</taglib-uri>
<taglib-location>/WEB-INF/tlds/mytag.tld</taglib-location>
</taglib>
</jsp-config>配置该没有错 因为使用的时候都没有报错但 不管把不把display设置为true 标签体的内容都不显示 这是为什么呢
import javax.servlet.jsp.tagext.BodyTagSupport;public class Status extends BodyTagSupport {
boolean display; public void setDisplay(boolean display) {
this.display = display;
}
public int doStarTag()
{
if(!display)
return SKIP_BODY;
else
return EVAL_BODY_BUFFERED;
}
public int DoEndTag() throws JspTagException
{
try
{
if(bodyContent!=null)
{
bodyContent.writeOut(bodyContent.getEnclosingWriter());
}
}
catch(java.io.IOException e)
{
throw new JspTagException("NO!");
}
return EVAL_PAGE;
}}
描述文件myTag.tld中的配置
<tag>
<name>status</name>
<tag-class>com.mybbs.jsptag.Status</tag-class>
<body-content>JSP</body-content>
<attribute>
<name>display</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>web.xml中的配置<jsp-config>
<taglib>
<taglib-uri>/MyTag</taglib-uri>
<taglib-location>/WEB-INF/tlds/mytag.tld</taglib-location>
</taglib>
</jsp-config>配置该没有错 因为使用的时候都没有报错但 不管把不把display设置为true 标签体的内容都不显示 这是为什么呢
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货