码迷,mamicode.com
首页 > 其他好文 > 详细

传统标签库功能

时间:2014-07-30 00:38:02      阅读:274      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   http   java   color   os   io   

bubuko.com,布布扣

 

bubuko.com,布布扣
 1 package cn.itcast.web.tag;
 2 
 3 import javax.servlet.jsp.JspException;
 4 import javax.servlet.jsp.tagext.IterationTag;
 5 import javax.servlet.jsp.tagext.Tag;
 6 import javax.servlet.jsp.tagext.TagSupport;
 7 
 8 //控制表前提执行5次
 9 public class TagDemo3 extends TagSupport {
10     int x=5;
11     @Override
12     public int doAfterBody() throws JspException {
13             
14             x--;
15             if(x>0){
16                 return IterationTag.EVAL_BODY_AGAIN;
17             }else{
18                 return IterationTag.SKIP_BODY;
19             }
20     }
21 
22     @Override
23     public int doStartTag() throws JspException {
24 
25         return Tag.EVAL_BODY_INCLUDE;
26     }
27     
28     
29 
30 }
TagDemo3
bubuko.com,布布扣
 1 package cn.itcast.web.tag;
 2 
 3 import java.io.IOException;
 4 
 5 import javax.servlet.jsp.JspException;
 6 import javax.servlet.jsp.tagext.BodyContent;
 7 import javax.servlet.jsp.tagext.BodyTag;
 8 import javax.servlet.jsp.tagext.BodyTagSupport;
 9 import javax.servlet.jsp.tagext.Tag;
10 
11 //修改标签体(把标签体改为大写)
12 public class TagDemo4 extends BodyTagSupport {
13 
14     @Override
15     public int doEndTag() throws JspException {
16 
17         BodyContent bc = this.getBodyContent();//得到标签体
18         String content = bc.getString();
19         content = content.toUpperCase();
20         
21         try {
22             this.pageContext.getOut().write(content);
23         } catch (IOException e) {
24             throw new RuntimeException(e);
25         }
26         
27         return Tag.EVAL_PAGE;
28         
29     }
30 
31     @Override
32     public int doStartTag() throws JspException {
33 
34         return BodyTag.EVAL_BODY_BUFFERED;
35     }
36     
37     
38 
39 }
TagDemo4
bubuko.com,布布扣
 1 <?xml version="1.0" encoding="UTF-8" ?>
 2 
 3 
 4 <taglib xmlns="http://java.sun.com/xml/ns/j2ee"
 5     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 6     xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"
 7     version="2.0">
 8     <description>A tag library exercising SimpleTag handlers.</description>
 9     <tlib-version>1.0</tlib-version>
10     <short-name>itcast</short-name>
11     <uri>/itcast</uri>
12     
13     <tag>
14         <name>viewIP</name>
15         <tag-class>cn.itcast.web.tag.ViewIPTag</tag-class>
16         <body-content>empty</body-content>
17     </tag>
18     <tag>
19         <name>TagDemo3</name>
20         <tag-class>cn.itcast.web.tag.TagDemo3</tag-class>
21         <body-content>JSP</body-content>
22     </tag>
23     <tag>
24         <name>TagDemo4</name>
25         <tag-class>cn.itcast.web.tag.TagDemo4</tag-class>
26         <body-content>JSP</body-content>
27     </tag>
28    
29   
30   </taglib>
itcast.tld

 

传统标签库功能,布布扣,bubuko.com

传统标签库功能

标签:des   style   blog   http   java   color   os   io   

原文地址:http://www.cnblogs.com/aineko/p/3876700.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!