您的位置:首页 > Web前端 > JavaScript

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 include string java c