1)使用自定义标签控制页面内容(标签体)是否输出
public void doTag() throws JspException, IOException {
// TODO Auto-generated method stub
//JspFragment jf=this.getJspBody();//得到标签体对象
//jf.invoke(this.getJspContext().getOut());
//jf.invoke(null);
}
2)简单标签控制该自定义标签后的JSP内容是否执行
创建一个标签处理器:
public void doTag() throws JspException, IOException {
// TODO Auto-generated method stub
//JspFragment jf=this.getJspBody();
//jf.invoke(null);如果没有标签体,抛异常
throw new SkipPageException();
}
tld文件进行描述
3)简单标签控制迭代
创建一个标签处理器
public void doTag() throws JspException, IOException {
// TODO Auto-generated method stub
JspFragment jf=this.getJspBody();
for(int i=0;i<count;i++)
jf.invoke(null);
}
增加一个属性:count
private int count;
public void setCount(int count) {
this.count = count;
}
tld文件进行描述
"10"
<csdn:demo8 count="${data}">
"<%=data+1%>" rt runtime
4)简单标签控制标签体的内容进行修改
创建一个标签处理器
public void doTag() throws JspException, IOException {
// TODO Auto-generated method stub
JspFragment jf=this.getJspBody();
//
StringWriter sw=new StringWriter();
jf.invoke(sw);
String content=sw.toString().toUpperCase();
JspWriter jw=this.getJspContext().getOut();
jw.write(content);
}
tld文件进行描述
二、带属性的标签
<csdn:demo8 count="8">
</csdn:demo8>
标签处理器中一定也得包含一个私有的属性count和setter方法
doTag()包含业务逻辑代码
tld文件:
<tag>
<name></name>
<tag-class>com.hbsi.web.tag.SimpleTagDemo8</tag-class>
<body-content></body-content>
<attribute>
<name></name>
<required>true|false</required>
<rtexprvalue>true|false</rtexprvalue>
</attribute>
</tag>
<csdn:demo10 date="2011-11-12"/>
SimpleTagDemo10:
Date date setDate(Date d)
IfTag:
boolean test;
setTest()
doTag(): if(test){
获取标签体,invoike()
}
共享一个变量boolean
<c:choose>
<c:when test="${user!=null}">
This is my JSP page. <br>
</c:when>
<c:other>
bbbbb
</c:other>
</c:choose>
<c:foreach>
</c:foreach>