I.                    BodyTag ¶õ

´Ü¼øű×(Simple Tag)´Â ¸öü¸¦ Çѹø¸¸ ó¸®ÇÏÁö¸¸, BodyTag ´Â ¸öü¸¦ ¿©·¯ ¹ø ó¸®ÇÒ ¼ö ÀÖ´Ù.

 

inteface

javax.servlet.jsp.tagext.BodyTag

+EVAL_BODY_TAG:int

+doInitBody:void

+setBodyContent(:javax.servlet.jsp.tagext.BodyContent):void
+doAfterBody():int

 

interface

javax.servlet.tagext.Tag

+EVAL_BODY_INCLUDE :int

+EVAL_PAGE:int

+SKIP_BODY:int

+SKIP_PAGE:int

+release():void

+getParent():javax.servlet.jsp.tagext.Tag

+getParent(:javax.servlet.jsp.tagext.Tag):void

+doEndTag():int

+doStartTag():int

+getPageContext(:javax.servlet.jsp.PageContext):void

 

BodyTag ÀÎÅÍÆäÀ̽º´Â Tag ÀÎÅÍÆäÀ̽º¸¦ »ó¼ÓÇÏ¿© ¸¸µé¾îÁö¸ç ¸î°¡ÁöÀÇ ¸Þ¼­µå¸¦ Á¦°øÇÑ´Ù.

BodyContent Ŭ·¡½º´Â ¸öü¸¦ ¿©·¯ ¹ø ó¸®ÇÒ ¼ö ÀÖµµ·Ï ÇÑ´Ù.

 

1.

 

 

SKIP_BODY

¸¦ ¸®ÅÏÇÒ¶§±îÁö ¼øȯ

 
setPageContext(javax.servlet.jsp.PageContext):void

2. setParent(javax.servlet.jsp.tagext.Tag):void

3. //setAttribute()

4. doStartTag():int

5. setBodyContent(javax.servlet.jsp.tagext.BodyContent):void

6. doInitBody():void

7. doAfterBody():int

8. doEndTag():int

9. release():void

 

ÄÁÅ×À̾ ÀÇÇؼ­ BodyTag ´Â BodyContent Ŭ·¡½º¸¦ °®´Âµ¥ BodyContent´Â ´ÙÀ½°ú

°°´Ù.

Javax.servlet.tagext.BodyContent

-enclosingWriter:javax.servlet.jsp.JspWriter

+BodyContent(:javax.servlet.jsp.JspWriter)

+getString():java.lang.String

+getReader():java.io.Reader

+writeOut(:java.io.Writer):void

+getEnclosingWriter():javax.servlet.jsp.JspWriter

+clearBody():void

 

BodyContent Ŭ·¡½º´Â JspWriter Ŭ·¡½º¸¦ »ó¼Ó¹Þ´Âµ¥ ÀÌ´Â ¸öü¸¦ ³ªÁß¿¡(?)ó¸®ÇÒ ¼ö ÀÖµµ·Ï ÇÒ ¼ö ÀÖµµ·ÏÇÑ´Ù.

BodyContent Ŭ·¡½ºÀÇ content ´Â getReader() ¸Þ¼­µå°¡ ¸®ÅÏÇÏ´Â Reader ¸¦ ÅëÇØ ÀÐÀ» ¼ö ÀÖ´Ù.

content´Â ¶ÇÇÑ getString()¸Þ¼­µå¸¦ È£ÃâÇϹǷνá StringÀ¸·Î ÀÐÀ» ¼ö ÀÖ´Ù.

BodyContent ÀÇ content ´Â clearBody()¸Þ¼­µå·Î ºñ¿ï ¼ö ÀÖ´Ù.

BodyContent ÀÇ content¸¦ ¾²±âÀ§Çؼ­´Â writer (getEnclosingWriter() ¸Þ¼­µå¿¡ ÀÇÇÏ¿© ¸®ÅϵǴ JspWriteró·³)

·Î writOut()¸Þ¼­µå¸¦ È£ÃâÇÒ ¼ö ÀÖ´Ù.

 

II.                  BodyTagÀÇ ÀÛ¼º

tag.LoopTag

-parent:Tag

-bodyContent:BodyContent

-pageContext:PageContext

-iterations:int=0

+LoopTag()

+setPageContext(PageContext:PageContext):void

+setParent(parent:javax.servlet.jsp.tagext.Tag):void

+setIterations(iterations:int):void

+doStartTag():int

+setBodyContent(bodyContent:BodyContent):void

+doInitBody():void

+doAfterBody():int

+doEndTag():int

+release():void

+getParent():javax.servlet.jsp.tagext.Tag

<LoopTag.java>

package tag;

 

import javax.servlet.jsp.*;

import javax.servlet.jsp.tagext.*;

 

public class LoopTag implements BodyTag{

       private Tag parent;

       private BodyContent bodyContent;

       private PageContext pageContext;

       private int iterations = 0;

 

       public LoopTag(){super();}

       public void setPageContext(PageContext pageContext){

                    this.pageContext = pageContext;

       }

       public void setParent(final javax.servlet.jsp.tagext.Tag parent){

                    this.parent = parent;

}

public void setIterations(int iteratons){

             this.iterations = iterations;

}

public int doStartTag() throws JspTagException{

             if(iterations > 0){

                           return EVAL_BODY_TAG;

             }else{

                           return SKIP_BODY;

             }

}

public void setBodycontent(BodyContent bodyContent){

             this.bodyContent = bodyContent;

}

public void doInitBody() throws JspTagException{}

public int doAfterBody() throws JspTagException{

             if(iterations > 1){

                           iterations--;

                          return EVAL_BODY_TAG;

             }else{

                           return SKIP_BOY;

             }

}

public int doEndTag() throws JspTagException{

             try{

                           if(bodyContent != null){

                                        bodyContent.writeOut(bodyContent.getEnclosingWriter());

                           }

             }catch(java.io.IOException e){

                           throw new JspTagException(¡°IO Error : ¡° + e.getMessage());

             }

             return EVAL_PAGE;

}

public void relese();

public javax.servlet.jsp.tagext.Tag getParent(){

             return parent;

}

}

 

III.                Tag Library ¼³¸íÀÚ µî·Ï

<mytag.tld>

<tag>

<name>loop</name>
<tagclass> tag.LoopTag</tagclass>
<bodycontent>JSP</bodycontent>
<info>A BodyTag for looping</info>
<attribute>

<name>iterations</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>

</attribute>

</tag>

 

IV.               JSPÆÄÀÏ ÀÛ¼º

<loop.jsp>

<%@ page contentType=¡±text/html;charset=EUC-KR¡± %>

<%@ taglib uri=¡±taglibExample¡± prefix=¡±mt¡±>

<HTML>

<HEAD>

       <TITLE>Loop Test</TITLE>

</HEAD>

<BODY BGCOLOR=¡±#FFFFFF¡±>

<HR>

       <mt:loop iterations=¡±5¡±>

                    Hello<BR>

       <mt:loop/>

<HR>

</BODY>

</HTML>