jsp自定义标签(一)
2011-11-08 18:53
337 查看
1、演示viewIP
1) 演示jsp中java代码实现
2) 自定义标签实现
2、演示传统自定义标签(jsp2.0以前的)
1) 使用自定义标签控制页面内容(标签体)是否输出,利用doStartTag()的返回值控制
returnthis.SKIP_BODY; //忽略标签体
return this.EVAL_BODY_INCLUDE; //执行标签体
2) 控制整个jsp的输出
利用doEndTag()的返回值控制
return this.SKIP_PAGE; //跳过页面标签后余下的jsp代码
returnthis.EVAL_PAGE; //继续执行余下jsp代码
3) 自定义标签实现内容(标签体)循环输出
利用Tag子接口Iteration中定义的doAfterBody()和返回值EVAL_BODY_AGAIN,SKIP_BODY实现
a) 先覆盖doStartTag()方法,返回EVAL_BODY_INCLUDE
b) 覆盖doAfterBody()
public int doAfterBody() throws JspException {
times++;
int result = this.EVAL_BODY_AGAIN;
if(times>4){
result = this.SKIP_BODY;
}
return result;
}
4) 自定义标签修改内容(标签体)EVAL_BODY_BUFFERED;
标签处理类:
c) 继承BodyTagSupport
d) 覆盖doStartTag(),并返回EVAL_BODY_BUFFERED;
e) 覆盖doEndTag()
public int doEndTag() throws JspException {
BodyContent bc = this.getBodyContent();
String c = bc.getString();
c = c.toUpperCase();
JspWriter out = this.pageContext.getOut();
try {
out.write(c);
} catch (IOException e) {
throw new RuntimeException(e);
}
return this.EVAL_PAGE;
}
相关文章推荐
- JSP自定义标签
- JSP自定义标签(Tag)
- JSP自定义标签配置
- JSP自定义标签
- JSP自定义标签
- JSP 自定义标签
- JSP 自定义标签
- 浅谈JSP自定义标签---白璐博客
- 心得10--jsp自定义标签介绍
- jsp自定义标签--->张国亮总结心得第四季
- Jsp自定义标签_防盗链标签
- jsp自定义标签实现java的switch……case实例
- jsp作业(4)---实现一个自定义标签
- JSP自定义标签(3)
- (转)掌握jsp自定义标签:(七)
- JSP自定义标签控制JSP内容显示&&自定义标签详解
- jsp自定义标签
- JSP自定义标签写写在JSP文件(.tag)中
- jsp自定义标签