I.                    µé¾î°¡¸é¼­

JSP ÀÇ ÀåÁ¡À̶ó¸é ºñÁî´Ï½º ·ÎÁ÷°ú ÇÁ¸®Á¨Å×ÀÌ¼Ç ·ÎÁ÷ÀÇ ºÐ¸®¶ó ÇÒ ¼ö ÀÖ½À´Ï´Ù.

Áï, °³¹ßÀÚ¿Í µðÀÚÀ̳ÊÀÇ ¿ªÇÒÀ» ¿ÏÀüÈ÷ ºÐ¸®ÇÏ¿© °³¹ßÀÚ´Â µ¿ÀûÀÎ ÆäÀÌÁö ±¸¼ºÀ» À§ÇÑ

³»ºÎ ·ÎÁ÷¿¡¸¸ Àü³äÇÒ ¼ö ÀÖÀ¸¸ç µðÀÚÀ̳ʴ HTMLÀÇ ±¸¼º¿¡¸¸ Àü³äÇÒ ¼ö ÀÖ´Ù´Â °ÍÀÔ´Ï´Ù.

¶ÇÇÑ ÆäÀÌÁö µðÀÚÀÎÀÌ ¹Ù²ð °æ¿ì °³¹ßÀÚ°¡ Âü¿©ÇÏ´Â °ÍÀÌ ¾Æ´Ï¶ó µðÀÚÀ̳ʰ¡ ´Üµ¶À¸·Î ó¸®

ÇÒ ¼ö ÀÖ´Ù´Â °ÍÀÔ´Ï´Ù. ±×¸®°í, ÆäÀÌÁö¿¡ ¹®Á¦°¡ ¹ß»ýÇßÀ» °æ¿ì °³¹ßÀÚ°¡ ÆäÀÌÁö¸¦ ¼öÁ¤ÇÏ´Â

°ÍÀÌ ¾Æ´Ï¶ó ºóÁî¿Í Tag Handler Ŭ·¡½º¸¸ ¼öÁ¤ÇÏ¸é µÇ´Â ÀåÁ¡µµ ÀÖ½À´Ï´Ù.

ÀÌ·¯ÇÑ °ÍÀº Custom Tag Library¸¦ ÅëÇØ °¡´ÉÇÑ °ÍÀÔ´Ï´Ù.

 

¹°·Ð, Custom Tag Library¸¦ ¸¸µé·Á¸é ASP³ª PHP¿¡ ºñÇØ ÈξÀ ¸¹Àº ÄÚµùÀÌ ÇÊ¿äÇÏÁö¸¸ ÃßÈÄ À§¿¡ ¾ð±ÞÇÑ Á¡µéÀ» »ý°¢ÇÑ´Ù¸é

ÃæºÐÈ÷ ±× ¿ªÇÒÀ» ÇÏÁö ¾ÊÀ»±î »ý°¢ÇÕ´Ï´Ù.

¸ðµç ÆäÀÌÁö¿¡ Custom Tag Library¸¦ Àû¿ëÇÏ´Â°Ç ¹«¸® Àϼöµµ Àֱ⠶§¹®¿¡ ÇÁ·ÎÁ§Æ®ÀÇ ¹üÀ§¿Í ±â´ÉÀ» »ý°¢Çؼ­ Á¶È­·Ó°Ô »ç¿ëÇØ¾ß ÇÒ °ÍÀÔ´Ï´Ù.

 

À̹ø °­Á¿¡¼­´Â ÀÌ·¯ÇÑ Tag ¿¡ ´ëÇؼ­ ¾Ë¾Æ º¸°Ú½À´Ï´Ù.

 

º» °­ÁÂÀÇ ³»¿ëÀº Orion »çÀÇ Æ©Å丮¾ó À» ¹ø¿ª ¹× ¼öÁ¤ ÇßÀ½À» ¹àÈ÷´Â ¹Ù ÀÔ´Ï´Ù.

ÀúÀ۱ǿ¡ ¹®Á¦°¡ µÈ´Ù¸é ¾Ë·ÁÁֽñ⠹ٶø´Ï´Ù.

 

II.                  Tag ¶õ ¹«¾ùÀΰ¡??

ű״ javax.servlet.jsp.tagext.Tag ÀÎÅÍÆäÀ̽º¸¦ ±¸ÇöÇÑ Å¬·¡½ºÀÌ´Ù.

ű״ JSPÆäÀÌÁö¿¡¼­ »ç¿ëµÇ´Â ±â´ÉµéÀ» ĸ½¶È­ ÇÏ¿© »ç¿ëµÇ´Âµ¥ ±× ¿¹·Î´Â Á¶°ÇºÐ±â,µ¥ÀÌÅͺ£À̽º Access , ¹Ýº¹µîÀÌ ±×°Í¿¡ ¼ÓÇÑ´Ù.

ű״ BodyTag , Tag(= Simple Tag – ´Ü¼øű×)·Î ³ª´µ¾î Áö´Âµ¥ À̹ø Àå¿¡¼­´Â ´Ü¼øű׸¸À» ³íÇϵµ·Ï ÇÏ°Ú´Ù.

 

Tag ´Â Çѹø¸¸ ¼öÇàµÇ´Â ¹Ý¸é¿¡ BodyTag ´Â ¿©·¯ ¹ø ¼öÇàµÉ¼ö ÀÖ´Ù.

 

III.                Tag ÀÇ ÀÛµ¿ ¸ÞÄ¿´ÏÁò

1.ÇöÀç pageContext¸¦ ¼³Á¤Çϱâ À§ÇØ setPageContext() ¸¦ »ç¿ëÇÑ´Ù.

2.¿¬°üµÈ Tag ÀÇ ºÎ¸ð¸¦ ¼³Á¤Çϱâ À§ÇØ setParent()¸¦ »ç¿ëÇÑ´Ù.

3.attribute ¼³Á¤

4.doStartTag() È£Ãâ – EVAL_BODY_INCLUDE ¿Í SKIP_BODY¸¦ ¸®ÅÏÇϸç, EVAL_BODY_INCLUDE¸¦ ¸®ÅÏÇϸé

¸öü¸¦ ¼öÇàÇϸç SKIP_BODY¸¦ ¸®ÅÏÇÏ¸é ¸öü¸¦ ¼öÇàÇÏÁö ¾Ê´Â´Ù.

5.doEndTag() È£Ãâ – EVAL_PAGE ¿Í SKIP_PAGE¸¦ ¸®ÅÏÇϸç, EVAL_PAGE¸¦ ¸®ÅÏÇϸé

JSPÆäÀÌÁö ¼öÇàÀ» °è¼ÓÇϸç SKIP_PAGE¸¦ ¸®ÅÏÇϸé ÆäÀÌÁö ¼öÇàÀ» ¸ØÃá´Ù.

6.release() È£Ãâ – Tag°¡ »ç¿ëÇÑ ÀÚ¿øÀ» ÀÚ¿øÀ» Á¤¸®Çϵµ·Ï ÇÏ´Â ¸Þ¼­µå

 

¿¹¿Ü¹ß»ý)

doStartTag() , doEndTag() => JspTagException ¹ß»ý

 

IV.               HelloWorld Tag ÀÇ ÀÛ¼º

tag.HelloWorldTag

-pageContext:PageContext
-parent:Tag

+HelloWorldTag()
+doStartTag():int
+doEndTag():int
+release():void
+setPageContext(pageContext:javax.servlet.jsp.PageContext):void
+setParent(parent:javax.servlet.jsp.tagext.Tag):void

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

 

 

 

 

 

 

 

 

 

 

 

          

 

Interface

javax.servlet.jsp.tagext.Tag

 

 

 

           (Âü°í) ¿ø¹®ÀÇ µµÇ¥¿Í È­»ìÇ¥´Â UML Ç¥±â¹ýÀ¸·Î ÀÛ¼ºµÇ¾î ÀÖÀ½

          

           À§ÀÇ ¸Þ¼­µå³ª¿­¼ø¼­´ë·Î Tag Handler Ŭ·¡½º¸¦ ÀÛ¼ºÇÑ´Ù.

            

             <HelloWorldTag.java>

 

package tag.HelloWorldTag;

import javax.servlet.jsp.*;

import javax.servlet.jsp.tagext.*;

 

// ¸öü°¡ ¾ø´Â ÅÂ±× Çڵ鷯 Ŭ·¡½º À̹ǷΠTag ÀÎÅÍÆäÀ̽º¸¦ ±¸ÇöÇÑ´Ù.

public class HelloWorldTag implements Tag{

       // ¸â¹ö º¯¼ö ¼±¾ð

       private PageContext pageContext;

       private Tag parent;

      

       public HelloWorldTag(){super();}

 

       // ¸öü¸¦ ó¸®ÇÏÁö ¾ÊÀ¸¹Ç·Î SKIP_BODY¸¦ ¸®ÅÏÇϵµ·Ï ÇÑ´Ù.

       // ¾Õ¼­ ¼³¸íÇßµíÀÌ ¿¹¿Ü󸮵µ Çϵµ·Ï ÇÑ´Ù.

       public int doStartTag() throws javax.servlet.jsp.JspTagException{

                    return SKIP_BODY;

       }

 

       // JSPÆäÀÌÁöÀÇ ³ª¸ÓÁö ºÎºÐÀÌ Ã³¸®µÇµµ·Ï EVAL_PAGE¸¦ ¸®ÅÏÇÑ´Ù.

       public int doEndTag() throws javax.servlet.jsp.JspTagException{

                    return EVAL_PAGE;           

}

public void release(){}

// JSP ÄÁÅ×À̳ʿ¡ÀÇÇÏ¿© È£ÃâµÇ¸ç Tag ÀÇ PageContext¸¦ ¼³Á¤Çϴµ¥ »ç¿ëµÈ´Ù.

// ÀÏ´Ü Tag´Â ÀÚ½ÅÀÇ PageContext¸¦ ±â¾ïÇÏ°í ÀÖ´Ù´Â »ç½Ç¸¸À» ¾Ë¾ÆµÎµµ·ÏÇÏÀÚ

public void setPageContext(final javax.servlet.jsp.PageContext pageContext){

             this.pageContext = pageContext;

}

 

// Áßø¿¬°üű׿¡ »ç¿ëµÇ´Â ¸Þ¼­µå ÀÌ´Ù. ÀÌÈÄÀÇ ¹®¼­¿¡¼­ ´Ù·ê °ÍÀÌ´Ù.

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

             return parent;

}

 

V.                 ű×Çڵ鷯 Descriptor ÀÛ¼º

<mytag.tld>

<?xml version="1.0" encoding="ISO-8859-1" ?>

<!DOCTYPE taglib      

       PUBLIC "-//Sun MicroSystems, Inc. //DTD JSP Tag Library 1.1//EN"       

       "http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd">

 

<taglib>

       <tlibversion>1.0</tlibversion>

       <jspversion>1.1</jspversion>

       <shortname>mt</shortname>

       <uri>WEB-INF/tlds/mytag.tld</uri>

       <info>My First Tag Library</info>

       <tag>

                    <name>helloworld</name>

                    <tagclass>tag.HelloWorldTag</tagclass>

                    <info>A Hello World Tag</info>

       </tag>

</taglib>

 

VI.               web.xml ¿¡ ű׶óÀ̺귯¸® ¼³¸íÀÚ ÆÄÀÏ µî·Ï

<web.xml>

 

<?xml version="1.0" encoding="ISO-8859-1"?>

 

<!DOCTYPE web-app

    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"

    "http://java.sun.com/j2ee/dtds/web-app_2.2.dtd">

 

<web-app>

       <taglib>

                    <taglib-uri>taglibExample</taglib-uri>

                    <taglib-location>/WEB-INF/tlds/mytag.tld</taglib-location>

       </taglib> 

</web-app>

 

VII.             Tag Çڵ鷯 »ç¿ëÇϱâ

<helloWorld.jsp>

 

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

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

<HTML>

<HEAD>

<TITLE>Hello World!</TITLE>

</HEAD>
<BODY BGCOLOR="#FFFFFF">

<HR>
<mt:helloWorld/>
<HR>

</BODY>

</HTML>

 

(ÁÖÀÇ) taglib ÀÇ uri´Â web.xml¿¡ µî·ÏµÈ ¼³¸íÀÚ ÆÄÀÏÀÇ uri¿Í ÀÏÄ¡½ÃÅ°µµ·Ï ÇÑ´Ù.

¿ø¹®Æ©Å丮¾óÀÇ °æ¿ì web.xml¿¡ ű׶óÀ̺귯¸® ¼³¸íÀÚ ÆÄÀÏ µî·Ï°úÁ¤ÀÌ »ý·«µÇ°í

´ë½Å jspÆÄÀÏÀÇ uri ¼³Á¤ºÎºÐÀ» ¹Ù·Î ű׶óÀ̺귯¸® ¼³¸íÀÚ ÆÄÀÏ°ú ¸ÅÇÎÀ» ½ÃÄÑÁÖ¾ú´Ù.

 

(ÀÛ¾÷µð·ºÅ丮¿¹)

tomcat           – webapps

                                 -tag_tu ( helloWorld.jsp)

                                               -WEB-INF (web.xml)

                                                            -classes

                                                                         -tag (HelloWorldTag.class)

                                                            -tlds (mytag.tld)

      

ºê¶ó¿ìÀú·Î °á°ú¸¦ È®ÀÎÇϽà ¹Ù¶õ´Ù.

http://localhost/tag_tu/helloWorld.jsp                   

 

(»ç¼³) ±âÁ¸ÀÇ Ä¿½ºÅÒ Å±×Çڵ鷯 ºÎºÐ¿¡ ´ëÇØ ¼³¸íµÈ ¹®¼­¸¦ ã¾Æº¸¾ÒÁö¸¸,

Ä¿½ºÅÒÅÂ±× ¸ÞÄ¿´ÏÁò¿¡ °¡Àå Ãæ½ÇÇß´ø ¹®¼­´Â ¿À¶óÀ̿»çÀÇ Æ©Å丮¾ó ÀÎ °Í °°´Ù.

»ç½Ç Ä¿½ºÅÒű׸¦ ÀÛ¼ºÇϴ°͵µ Áß¿äÇÏÁö¸¸ ±âº» ¸ÞÄ¿´ÏÁò¿¡ Ãæ½ÇÇÏÁö ¾ÊÀ¸¸é ÀÌÇصÇÁö ¾Ê´Â ºÎºÐÀÌ »ó´ç¼ö ÀÖÀ» °Í °°´Ù.

°á°úÈ®Àεµ Áß¿äÇÏÁö¸¸ ±âº» ¸ÞÄ¿´ÏÁòÀ» È®½ÇÈ÷ ÀÌÇØÇϱ⠹ٶõ´Ù(ƯÈ÷ ÀÛµ¿ ¼ø¼­..)

 

º» °­ÁÂÀÇ ³»¿ëÀº Orion »çÀÇ Æ©Å丮¾ó À» ¹ø¿ª ¹× ¼öÁ¤ ÇßÀ½À» ¹àÈ÷´Â ¹Ù ÀÔ´Ï´Ù.

ÀúÀ۱ǿ¡ ¹®Á¦°¡ µÈ´Ù¸é ¾Ë·ÁÁֽñ⠹ٶø´Ï´Ù