Site Search :
Standard Enterprise XML Methodology Pattern Setting Tunning Other
Article Contributors
GuestBook
Javapattern Maven
XSourceGen Dev
JetSpeed Test
JLook Image
jLook Family Site


Web Application Framework°³¹ß¹æ¹ý(2)-LifeCycle,Controller
 
¾È³çÇϽʴϱî? ÀüÆí¿¡ À̾ À̹ø¿¡´Â WAF¿¡ ´ëÇÑ 2Â÷ ³»¿ëÀ» ÁøÇàÇÏ°íÀÚ ÇÕ´Ï´Ù. Ç×»ó »ý°¢ÀÌÁö¸¸ ¿©·¯ºÐµé²² ²À ÇÊ¿äÇÑ Á¤º¸µéÀ» º¸¿©ÁÖ°íÀÚ Çϴµ¥ ¾ó¸¶³ª ¸¸Á·ÇϽǷ±Áö Àß ¸ð¸£°Ú½À´Ï´Ù. ( 2003/03/24 ) 510
Written by ienvyou - ÃÖÁö¿õ
1 of 1
 

¾È³çÇϽʴϱî? ÀüÆí¿¡ À̾ À̹ø¿¡´Â WAF¿¡ ´ëÇÑ 2Â÷ ³»¿ëÀ» ÁøÇàÇÏ°íÀÚ ÇÕ´Ï´Ù.
Ç×»ó »ý°¢ÀÌÁö¸¸ ¿©·¯ºÐµé²² ²À ÇÊ¿äÇÑ Á¤º¸µéÀ» º¸¿©ÁÖ°íÀÚ Çϴµ¥ ¾ó¸¶³ª ¸¸Á·ÇϽǷ±Áö
Àß ¸ð¸£°Ú½À´Ï´Ù.

ÀÚ, ´Ù½Ã ¹Ý¸»·Î ½ÃÀÛÇÕ´Ï´Ù.

¢º Framework Lifecycle¼³°è

Áö³­ Æí¿¡¼­´Â ÇÁ·¹ÀÓ¿÷À̶õ µµ´ëü ¹«¾ùÀ̸ç, ¾î¶°ÇÑ Æ¯Â¡À» °¡Á³´ÂÁö¸¦ »ìÆ캸¾Ò´Ù.
¶ÇÇÑ °³¹ßÁÖº¯»óȲ¿¡ ´ëÇÏ¿©¼­µµ ¾Ë¾Æº¸¾Ò´Âµ¥, »ç½Ç °³¹ßÀ̶õ °ÍÀÌ ¹«´ë»Ç°¡ °¡´ÉÇÒ·±Áöµµ
¸ð¸£Áö¸¸ ¼³°è»ç»ó¸¸Å­ Áß¿äÇÑ Ç׸ñÀÌ ¾øÁö ¾Ê³ªÇÑ´Ù. 

ÇÁ·ÎÁ§Æ®¶õ °ÍÀÌ ÇϳªÀÇ ÁýÀ» Áþ´Â °Í°ú °°¾Æ¼­ ¶Ù¾î³­ °¨°¢À» °¡Áø °ÇÃ༳°è»ç¿¡ ÀÇÇÏ¿© Ä¡¹ÐÇÏ°Ô 
¼³°èµÇ¾îÁö°í ¼³°è»ç»óÀ» ÃæºÐÈ÷ ¹Ý¿µÇÒ ¼ö ÀÖ´Â ÇöÀå°¨µ¶À» °í¿ëÇÏ¿©, ¾Æ³¦¾ø´Â ÅõÀÚ°¡ ÀÌ·ç¾îÁ³À»¶§
ºñ·Î¼Ò Á¤¸» ÀßÁö¾îÁø ÁýÀ» Áþ´Â °Í°ú °°À½ÀÌ´Ù. 
´ç¿¬È÷ ¼³°è°¡ ÀߵǾîÁ® ÀÖ°í, ÁÁÀº ½Ã°ø¾÷ÀÚµéÀÌ ºÙ´Â´Ù´Â °Ç ¼ÒÇÁÆ®¿þ¾î¿¡¼­µµ ¸¶Âù°¡Áö·Î
ÁÁÀº ¾ÆÅ°ÅØÆ®¾Æ·¡¿¡¼­ ¿ª·®À» ÃæºÐÈ÷ ³¾ ¼ö ÀÖÀ» ¸¸ÇÑ °³¹ßÀÚµéÀÌ ÀÖ´Ù´Â ¸»·Î Ç¥ÇöµÇ¾îÁú ¼ö ÀÖ´Ù.

ÄÛ¹øÀº "Á¦´ë·Î µÈ »ç¶÷µé¸¸ ÀÖ´Ù¸é °¡¸¸È÷ µÎ¾îµµ ÇÁ·ÎÁ§Æ®´Â ¼º°øÇϱ⠸¶·ÃÀÌ´Ù"¶ó´Â À̾߱⸦
ÇÑ´Ù.

´ç½ÅÀº ÁøÁ¤À¸·Î À§ÀÇ ¸»À» ½Ç°¨ÇÒ ¼ö Àִ°¡? ÇÁ·ÎÁ§Æ®´Â ´Éµ¿ÀûÀ̾î¾ß ÇÑ´Ù.

°¢¼³ÇÏ°í, ¼³°èÀÛ¾÷À» Çѹø Çغ¸µµ·Ï ÇÏÀÚ.
°¡Àå Áß¿äÇÑ °ÍÀÌ ¶óÀÌÇÁ»çÀÌŬÀÏ ¼ö Àִµ¥, ÀÌ¹Ì ¿ì¸®°¡ WAF¸¦ ¸¸µé¾î³¾¶§ ¼­ºí¸´ ¿£ÁøÀ» ÅëÇÏ¿© 
client request, responseÁ¤º¸´Â Çѹø °É·¯Á® ¿ì¸®°¡ ¸¸µé¾î³»´Â ¾ÖÇø®ÄÉÀ̼ÇÀ¸·Î Àü´ÞµÇ¾îÁú °ÍÀÌ´Ù.

±âº»ÀûÀÎ ½Ã³ª¸®¿À¸¦ º¸¾Ò¾úÀ» ¶§ Áß¾ÓÁýÁßÀûÀ¸·Î request¸¦ ¹Þ¾Æ¼­ ó¸®ÇÑ ÈÄ JSP·Î PresentionÀ» 
ÇÑ´Ù°í ÇÏ¿´´Ù. ÀÌ°ÍÀÌ ¹«¾ùÀ» ÀǹÌÇϴ°¡? 

°³¹ßÀÚ´Â ¿ì¼± µé¾î¿Â reqeust¸¦ ÀÌ¿ëÇÏ¿© BLÀ» ó¸®ÇÏ°í, JSPÃøÀ¸·Î request¿¡ attribute¸¦ ¼¼ÆýÃŲ´Ù´Â
ÀǹÌÀÌ°í, È­¸éÀÇ ±¸¼ºÀº templateÆäÀÌÁö¸¦ ÀÌ¿ëÇÑ Á¶¸³¹æ½ÄÀÌ´Ù¶ó´Â ÈùÆ®¿¡¼­ include¼Ó¼ºÀÌ 
ÇÊ¿äÇÏ´Ù´Â °ÍÀ» ¾Ë°ÍÀÌ´Ù.
±×·¯¸é ¿©±â¼­ ¾î¶² °á°ú°¡ µµÃâµÇ´Â°¡? ÇÑ°¡ÁöÃø¸éÀ̱ä ÇÏÁö¸¸ Model 2¹æ½ÄÀ̱⠶§¹®¿¡ Dispatcher¹æ½ÄÀÇ 
µµÀÔÀÌ Çϳª Á¸ÀçÇÏ°Ô µÈ´Ù. ÀÌ dispatcherÀÇ ÇÁ·¹ÀÓ¿÷»óÀÇ À§Ä¡´Â ¾îµðÀΰ¡? ¸Ç ¸¶Áö¸·ºÎºÐÀÌ´Ù.

ÀÌ·¯ÇÑ ºÎºÐÀ» ÄÚ´õµé¿¡°Ô ¸Å¹ø ÀÛ¼ºµÇ´Â include, forwardºÎºÐÀ» ÀÛ¼ºÇÏ°Ô ÇÒ°ÍÀΰ¡? ±×·¸°Ô »ý°¢ÇÑ´Ù¸é
´ç½ÅÀ» Ãʺ¸¾ÆÅ°ÅØÆ®¿¡ Áö³ªÁö ¾Ê´Â´Ù. ±×·¯¸é extends¸¦ ½ÃÄѼ­ »óÀ§Å¬·¡½º¿¡¼­ »ç¿ëÇÏ°Ô ÇÒ°ÍÀΰ¡?
Èì.. ±¦ÂúÀº ¹æ¹ýÀ̱⵵ ÇÏÁö¸¸ ±×·¯ÇÑ °Í±îÁö °³¹ßÀڵ鿡°Ô º¸¿©ÁÙ ÇÊ¿ä´Â ¾ø´Ù. 
Ãß»óÈ­ÀÇ Á¤µµ¸¦ ¾ÆÁÖ ²ø¾î¿Ã¸®ÀÚ´Â °ÍÀÌ´Ù. °³¹ßÀÚµé °¡¶àÀ̳ª ¸Ó¸®¾Æǵ¥ ÀÌ·¯ÇÑ °Í±îÁö ½Å°æ¾²°Ô
ÇÑ´Ù´Â °ÍÀº ¼³°èÀÚ°¡ "³ª»Û ³ð" ¼Ò¸®¸¦ µéÀ» ¼ö ÀÖ´Â ÀÌÀ¯°¡ µÉ¼öµµ ÀÖÀ» °ÍÀÌ´Ù.

ÀÚ, ±×·³ ³¡ºÎºÐ¿¡ ´ëÇÑ °ÍÀº ±×·¸°Ô 󸮵ǾîÁö°í, BL(Business Logic)À» ó¸®ÇÔ¿¡ À־ ÇÁ·Î±×·¥ÀÛ¼º¿¡
°³¹ßÀÚµéÀÌ ÇÊ¿äÇÑ API°´Ã¼µéÀº ´ëü ¹«¾ùÀΰ¡? 
ControlºÎºÐÀÌ framework¿¡ ÀÇÇÏ¿© Àü´ÞµÇ¾îÁö°í °³¹ßÀÚµéÀÌ ½ÇÁ¦ ÇÊ¿äÇÑ °´Ã¼¸¦ ÀûÀýÇÏ°Ô ¿ä¸®ÇÏ¿©
´øÁ®Áà¾ß ÇÒ Ã¥ÀÓÀÌ ÇÁ·¹ÀÓ¿÷¿¡ ÀÖ´Ù. 
´ëÃæ ³ª¿­ÇØ º»´Ù¸é context, request, responseÁ¤µµ¸é µÉ±î? ¾î¶»°Ô »ý°¢Çϴ°¡? 
´ç¿¬È÷ À§ÀÇ 3°¡Áö¸¸ À־ ¿¬°áµÈ API»ó¿¡¼­ ¸ðµç °´Ã¼¸¦ »Ì¾Æ³¾ ¼ö ÀÖ´Ù. 

¼­ºí¸´ÀÇ lifecycleÀÌ °¡Áö´Â init(), service(), destory()¸Þ¼Òµå¸¦ ÀûÀýÇÏ°Ô ¿ä¸®Çغ¸ÀÚ.
ÃʱâÈ­¿Í Á¾·áºÎºÐÀº ÇÊ¿ä¿¡ ÀÇÇÏ¿© °³¹ßÀڵ鿡°Ô ÄÚµùÇϵµ·Ï ÁÖ¹®ÇÏÀÚ. ½ÇÁ¦ Áß¿äÇÑ °ÍÀº serviceÀε¥
¾Æ¹«°Íµµ ÇÊ¿ä¾øÀÌ µé¾î¿À´Â request¿¡¼­ ¿øÇÏ´Â °´Ã¼µîÀ» »Ì¾Æ³½ÈÄ request.setAttribute()À» ÀÌ¿ëÇÏ¿©
jspÃøÀ¸·Î µ¥ÀÌÅ͸¦ ½Ç¾îº¸³½´Ù´Â »ç»ó¸¸À» °®ÀÚ

¾Æ·¡¿Í °°Àº ÄÚµùÀÌ ÀÌ·ç¾îÁöµµ·Ï ÇÏ´Â °ÍÀÌ´Ù.

    public void service(){
        //request¿¡¼­ ¿øÇÏ´Â µ¥ÀÌÅ͸¦ »Ì¾Æ³½´Ù.

        // EJB BusinessÈ£Ã⠶Ǵ Data Access Object¸¦ ÀÌ¿ëÇÏ¿© °á°ú¸¦ ¾ò¾î³½´Ù

        // ¾ò¾î³½ °á°ú¸¦ request¿¡ ¼¼ÆÃÇÏ¿© jsp·Î º¸³½´Ù.
    }


À§ÀÇ Äڵ常À¸·Î ¸ðµç 󸮰¡ ³¡³ªµµ·Ï ÇÏÀÚ´Â °ÍÀÌ´Ù. ±×·¸´Ù¸é forwadingµÉ ÆäÀÌÁö ¹× ±âº»ÀûÀÎ
¼³Á¤Á¤º¸µîÀº ´ëü ¾îµð¿¡ ±â¼úÇÑ´Ù´Â °ÍÀΰ¡? 1Æí¿¡¼­ XMLÀ» ÀÌ¿ëÇÏ¿© ±â¼úÇÑ´Ù°í ÇÏ¿´´Ù.

ÀÚ, °á·ÐÀ» Áö¾îº¸ÀÚ. ÃÖ´ëÇÑ ½ÉÇÃÇÏ°Ô ±¸¼ºÇϱâ À§ÇÏ¿© ±âº»ÀûÀ¸·Î ÇÁ·Î±×·¡¸Óµé¿¡°Ô ÇÊ¿äÇÑ
context, request¸¦ ³Ñ°ÜÁÖ´Â °ÍÀ¸·Î °á·ÐÀ» Áö¾îº¸ÀÚ.

º¹ÀâÇÑ ¶óÀÌÇÁ»çÀÌŬÀ» Á¤ÀÇÇϸé Àд ´ç½Åµé¸¸ º¹ÀâÇϱ⠶§¹®¿¡ 3°¡Áö ¸Þ¼Òµå¸¦ ÀÚµ¿À¸·Î 
È£ÃâÇÒ ¼ö ÀÖµµ·Ï Á¤ÀÇÇÏÀÚ.

³î»õ´Â ¾Æ·¡¿Í °°ÀÌ Á¤ÀÇÇÏ°í ±× ¸Þ¼ÒµåµéÀ» Carouser FrameworkÀÇ ¶óÀÌÇÁ»çÀÌŬÀ̶ó ÀÓ¸íÇϳë¶ó.
Âü°í·Î response¿¡ ´ëÇÑ Çڵ鸵 ±â´ÉÀ» ³ÖÁö ¾Ê¾Ò´Ù.

        setServletContext(context);
        perform(req);
        doEnd(req);


À§ÀÇ Á¤µµ·Î ¶óÀÌÇÁ»çÀÌŬÀ» Á¤ÀÇÇÏ¿© ÀÚµ¿À¸·Î frameworkÀÌ ½ÇÁ¦ ¼³Á¤µÈ Ŭ·¡½ºµéÀ» ÀÌ¿ëÇÏ¿©
È£ÃâÀ» À¯µµÇϵµ·Ï ÇÏÀÚ.

¢º Framework ConfigurationÀ» ÀÌ¿ëÇÑ Controller½Ã³ª¸®¿À

ÀÚ, ÀÌÁ¦ 3°¡Áö ¸Þ¼Òµå¸¦ ÀÌ¿ëÇÏ¿© ¶óÀÌÇÁ»çÀÌŬÀ» Á¤ÀÇÇغôÙ. ÀÌÁ¦´Â ±× ¶óÀÌÇÁ»çÀÌŬÀÇ
È帧À» Å» ¼ö ÀÖ´Â Á¦¹Ý ȯ°æ¿¡ ´ëÇÏ¿© ³íÀÇÇغ¸ÀÚ. 
±âº»ÀûÀ¸·Î´Â XMLÀ» ¾µ°ÍÀÌ´Ù¶ó°í ¿©·¯ºÐµé¿¡°Ô À̾߱âÇߴµ¥, ¿©±â¼­ »ç¿ëµÉ °Í ¸»°í ±âº»ÀûÀ¸·Î
¿£Áø¿¡¼­ »ç¿ëµÇ´Â XMLÀº ¹«¾ùÀΰ¡? 

web.xml ÀÌ ¸Â´Â°¡? ±×°÷¿¡´Â filter, listenerµîÀÇ Ãʱ⿡ ·ÎµùµÇ¾îÁ®¾ß ÇÒ Å¬·¡½º ¹× °¢Á¾ ȯ°æÁ¤º¸µéÀÌ
µé¾î°¡°Ô µÈ´Ù. °Å±â¿¡ ¿ì¸®´Â framework¿£ÁøÀ» ½ÃÀÛÇÁ·Î±×·¥Çü½ÄÀ¸·Î µî·Ï½ÃÄÑ ¸ðµç Á¤º¸¸¦ ·ÎµùÇÏ°Ô
ÇÒ ¿¹Á¤ÀÌ´Ù.



  1. ¼­ºí¸´ ÄÁÅ×À̳ʰ¡ µ¿ÀÛÀ» ½ÃÀÛÇÏ¿© web.xmlÀÇ È¯°æÁ¤º¸¸¦ ÀоîµéÀδÙ. ÀÌ web.xml¿¡´Â ±âº»ÀûÀ¸·Î ÇÁ·¹ÀÓ¿÷ ¿£ÁøÀ» startupÀ¸·Î žÀç½ÃÄÑ ³õ´Â´Ù
  2. ÇÁ·¹ÀÓ¿÷¿£ÁøÀÌ ½ºÅ¸Æ® µÇ¾îÁü°ú µ¿½Ã¿¡ ¹Ì¸® ¼³Á¤µÈ XML ConfigurationÀ» ÀÌ¿ëÇÏ¿© »ç¿ëµÉ Ŭ·¡½º¹× ¸ðµç ±¸µ¿Á¤º¸¸¦ ¸Þ¸ð¸®»ó¿¡ ·ÎµåÇϵµ·Ï ÇÑ´Ù.
  3. ÄÁÅ×À̳ʷΠBL¿¡ ´ëÇÑ ¿äûÀÌ µé¾î¿Ã½Ã ÇÁ·¹ÀÓ¿÷Àº µé¾î¿Â URI¸¦ Çؼ®ÇÏ¿© ÇØ´ç URI¿¡ ´ëÇÑ ±¸µ¿Å¬·¡½º ÀÇ °´Ã¼¸¦ »ý¼ºÇÏ°í, ¶óÀÌÇÁ »çÀÌŬ¿¡ ´ëÇÑ È£ÃâÀ» ½ÃµµÇÑ´Ù.
  4. 󸮵ǾîÁø ·ÎÁ÷ÀÇ °á°ú°ªÀº ¹Ì¸® Á¤ÀÇµÈ XML ConfigurationÀÇ JSPÆäÀÌÁöÃøÀ¸·Î ÀÚµ¿À¸·Î ¼¼ÆõǾîÁ® ³Ñ¾î°¡µµ·Ï ÇÑ´Ù
À§¿¡¼­ XMLÀ» ÀÌ¿ëÇÏ¿© frameworkÀÇ configurationÀ» Àâ´Â´Ù°í ÇÏ¿´´Ù. ±âº»ÀûÀ¸·Î µÎ°¡ÁöÀÇ xmlÀÌ ÇÊ¿äÇÒ°ÍÀ¸·Î º¸ÀÌ´Â Çϳª´Â request URI°¡ ½ÇÁ¦ µé¾î¿ÔÀ» °æ¿ì ¾î¶² Ŭ·¡½º·Î BLÀ» ó¸®ÇØ¾ß ÇÒÁö¸¦ °áÁ¤ÇÏ´Â ÆÄÀÏ°ú, ó¸®µÈ °á°ú°¡ ¾î¶² JSP·Î ¸ÅÇεǾîÁ®¾ß ÇÒÁö¸¦ °áÁ¤ÇÏ´Â ¼³Á¤ÆÄÀÏ·Î ³ª´­¼ö ÀÖ´Ù. ÀÌ·± ±â¹ýÀº ¾îµð¿¡ Àû¿ëµÇ¾î Àִ°¡? Sun blueprintÀÇ petstore¹× Apache Struts Framework¿¡¼­µµ ÀÌ ±â¹ýÀÌ »ç¿ëµÇ¾îÁö°í ÀÖ´Ù. ¿ì¸®´Â ÀÌ¹Ì web.xmlÀÇ servlet-mapping¼³Á¤¿¡ ¾Æ·¡¿Í °°Àº url¸íÀÌ µé¾î¿À¸é ÇØ´ç Ŭ·¡½º°¡ ÀÚµ¿À¸·Î ½ÇÇàµÇµµ·Ï ¹Ì¸® ¼³Á¤À» ÇÏÀÚ. ÂüÁ¶ : web.xml

<!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>

  <servlet>
    <icon>
      <small-icon>FrameworkEngine</small-icon>
      <large-icon>FrameworkEngine</large-icon>
    </icon>
    <servlet-name>Engine</servlet-name>
    <display-name>FrameworkEngine</display-name>
    <servlet-class>com.javapattern.framework.FrameworkEngine</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>

  <servlet>
    <icon>
      <small-icon>FrameworkComposer</small-icon>
      <large-icon>FrameworkComposer</large-icon>
    </icon>
    <servlet-name>Composer</servlet-name>
    <display-name>FrameworkComposer</display-name>
    <servlet-class>
    com.javapattern.framework.composer.FrameworkComposer
    </servlet-class>
    <load-on-startup>2</load-on-startup>
  </servlet>



  <servlet-mapping>
    <servlet-name>Engine</servlet-name>
    <url-pattern>*.main</url-pattern>
  </servlet-mapping>

  <servlet-mapping>
    <servlet-name>Composer</servlet-name>
    <url-pattern>*.view</url-pattern>
  </servlet-mapping>

  <session-config>
    <session-timeout>20</session-timeout>
  </session-config>

</web-app>
            
        
±×·¸´Ù¸é ±×·¯ÇÑ URIÁ¤º¸¸¦ Çؼ®ÇÏ¿© ¾î¶² Ŭ·¡½º¸¦ ±¸µ¿½ÃųÁö ȯ°æÀ» ¾î¶»°Ô ¼³Á¤ÇÏ¸é µÉ±î? ¾Æ·¡Ã³·³ °£´ÜÇÏ°Ô Á¤ÀÇÇغ¸µµ·Ï ÇÏÀÚ. ÂüÁ¶:request_config.xml

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

<request-root>
	<request name="test" nextJsp="test.view" isLogin="false">
		<action-class>ccc</action-class>
	</request>
	<request name="viewRequestList" nextJsp="list.view" >
		<action-class>temporary.RequestAdminAction</action-class>
	</request>

</request-root>
   
<request-root> : Root element·Î¼­ ÇÏÀ§ ¿ä¼Ò·Î »ç¿ëÀÚÀÇ request½Ã 󸮵Ǿî¾ß ÇÒ Á¤º¸ <request> : AttributeÁ¤º¸·Î name, nextJsp, isLoginÀ» °¡Áö°í ÀÖÀ¸¸ç, ÇÏÀ§ element·Î action-class¸¦ °¡Áö°í ÀÖ´Ù. - name : ÇØ´ç request¸¦ À¯ÀÏÇÏ°Ô ½Äº°ÇÒ ¼ö ÀÖ´Â À̸§¿ä¼Ò - nextJsp : Action-beanÀÇ business logicó¸®ÈÄ ¾î¶² È­¸éÀ» º¸¿©ÁÙ °ÍÀÎÁö¸¦ ¼³Á¤ÇÏ´Â ºÎºÐ º¸Åë È®ÀåÀÚ .viewÀÇ ÇüŸ¦ °¡Áø ÆäÀÌÁö·Î ¼³Á¤ÀÌ µÇ¸é .view¿¡ ´ëÇÑ ³»¿ëÀº webpages_config.xmlÆÄÀÏÀ» ÀÌ¿ëÇÏ¿© ¼¼ÆÃÇϵµ·Ï ÇÏÀÚ. - isLogin : ÇØ´ç request URIÀԷ½à action-beanŬ·¡½º¸¦ ó¸®ÇÒ °æ¿ì loginÀÌ ÇÊ¿äÇÑ ÆäÀÌÁö¿¡ ´ëÇÑ ¼³Á¤Á¤º¸¸¦ ³ÖÀ» ¼ö ÀÖµµ·Ï ÇϳªÀÇ ¼Ó¼º°ªÀ¸·Î¼­ Á¤ÀÇ <action-class> : ÀÌ°÷¿¡´Â ¿©·¯ºÐµéÀÌ °³¹ßÇÑ action-classÆÄÀÏÀÇ À̸§ÀÌ À§Ä¡. ÆÐÅ°Áö¸íÀ» Æ÷ÇÔÇÑ Å¬·¡½ºÀ̸§ÀÌ ÁÖ¾îÁ®¾ß Çϸç request¼³Á¤½Ã action-classűװ¡ Á¸ÀçÇÑ´Ù¸é engineÀº lifecycle¿¡ ÀÇÇÏ¿© ¼¼°¡Áö ¸Þ¼Òµå(À§ÀÇ ¶óÀÌÇÁ»çÀÌŬ¿¡¼­ ¼³¸í)¸¦ ÀÚµ¿ÀûÀ¸·Î È£ÃâÇϵµ·Ï ÇÑ´Ù. Áï ÁÖ¼Òâ¿¡ viewRequestList.mainÀ̶ó´Â ÀÔ·ÂÀÌ µé¾î¿À°Ô µÇ¸é ÀÚµ¿À¸·Î ¿£ÁøÀº temporary.RequestAdminActionÀ̶ó´Â Ŭ·¡½ºÀÇ °´Ã¼¸¦ »ý¼ºÇÑ ÈÄ ±× Ŭ·¡½º°¡ °¡Áø setServletContext, perform, doEnd¸Þ¼Òµå¸¦ Â÷·Ê·Î ½ÇÇà½ÃÅ°°í, ±× BLÀ» ó¸®ÇÒ viewÃøÀ¸·Î list.view¸¦ ÀÌ¿ëÇÏ¿© ó¸®Çϰڴٴ ȯ°æ¼³Á¤ÀÌ´Ù. Struts ¹× Petstore¸¦ Á¶±ÝÀ̳ª¸¶ °øºÎÇÑ »ç¶÷À̶ó¸é ½±°Ô ÀÌÇØÇÒ ¼ö ÀÖÀ» °ÍÀÌ´Ù. ±×·¸´Ù¸é xx.view´Â ¾î¶»°Ô 󸮵Ǵ°¡? À§ÀÇ web.xml¿¡¼­ È®ÀåÀÚ view°¡ µé¾î¿À°Ô µÇ¸é ÀÚµ¿À¸·Î com.javapattern.framework.composer.FrameworkComposerŬ·¡½º°¡ µ¿ÀÛÀÌ µÇµµ·Ï ¹Ý¿µ½ÃÄÑ ³õ¾Ò´Ù. À§ÀÇ Composer¿¡¼­´Â µé¾î¿À´Â request¸¦ Àоîµé¿© ÀÚ½ÅÀÌ º¸¿©Áà¾ß ÇÒ ÆäÀÌÁö¿¡ ´ëÇÑ Á¤º¸¸¦ ÀÌ¿ëÇÏ¿© °¢°¢ÀÇ jspÆÄÀϵéÀ» ÇϳªÀÇ ÅÛÇø´À» ÀÌ¿ëÇÏ¿© ºê¶ó¿ìÁ®¿¡ º¸¿©Áú ¼ö ÀÖµµ·Ï ¸¸µé¾î³»°Ô ÇÏ¸é µÉ°ÍÀÌ´Ù. ÂüÁ¶ : webpage_config.xml


<?xml version="1.0" encoding="euc-kr"?>

<webpage-definitions>
  
<!-- Sample -->
  <webpage>
  	<name>test</name>
  	<description>¼³¸í</description>
  	<title>È­¸é Á¦¸ñ</title>
	<layout>/template.jsp</layout>
  	<page key="header" 	url="/sample/header.jsp"/>
  	<page key="menu" 	url="/sample/menu.jsp"/>
  	<page key="body" 	url="/sample/body.jsp"/>
	<page key="sidebar" 	url="/sample/sidebar.jsp"/>
  	<page key="footer" 	url="/sample/footer.jsp"/>
  </webpage>
<!-- Sample end. -->
<webpage>
  	<name>poll.admin</name>
	<layout>/template.jsp</layout>
  	<page key="menu" 	url="/menu.jsp"/>
  	<page key="body" 	url="/component/poll/admin/pollAdmin.jsp"/>
  </webpage>

</webpage-definitions>
   
À§ÀÇ È¯°æ¼³Á¤ Á¤º¸´Â È­¸éÀÇ ·¹À̾ƿôÀ» ±¸¼ºÇÒ °æ¿ì FrameworkComposer Ŭ·¡½º¸¦ ÀÌ¿ëÇÏ¿© presentationÀ» ±¸¼ºÇÏ´Â Áß¿äÁ¤º¸ÀÌ´Ù. webpage tagÀÇ °æ¿ì Áß¿äÇÑ element¸¦ °¡Áö°í ÀÖ´Ù. - name : request½Ã µé¾î¿À´Â URIÀÇ nameÀ¸·Î¼­ ÆäÀÌÁö¸¦ ½Äº°ÇÏ´Â °¡Àå Áß¿äÇÑ Á¤º¸ÀÌ´Ù - description : ÀÌ À¥ ÆäÀÌÁö¿¡ ´ëÇÑ °³¿ä¸¦ »ç¿ëÇÒ ¼ö ÀÖ´Ù. ÁÖ¼®ÀÇ Àǹ̷Π»ý°¢ÇÏÀÚ. - title : À¥ºê¶ó¿ìÁ®¿¡ ³ªÅ¸³ª´Â html titleÁ¤º¸¸¦ ¼³Á¤ - layout : º¸¿©Áö´Â À¥ ÆäÀÌÁö´Â ¿©·¯ °¡Áö templateÇüÅ·Π±¸¼ºµÇ¾îÁú ¼ö ÀÖÀ¸¹Ç·Î ¼­·Î ´Ù¸¥ ·¹À̾ƿôÀ» °¡Áø ÆäÀÌÁö°¡ ÇÊ¿äÇÏ´Ù¸é ÀÌ ºÎºÐ¿¡ ¼³Á¤Çϵµ·Ï ¸¸µç´Ù. - page : º¸Åë jspÆÄÀÏ¿¡ ´ëÇÑ urlÀ» °¡Áö°í ÀÖÀ¸¸ç, Áߺ¹µÇ¾î ¼±¾ðµÇ¾î Áú ¼ö ÀÖµµ·Ï ÇÑ´Ù. ±âº»ÀûÀ¸·Î 5°³ÀÇ ·¹À̾ƿôÀ¸·Î À¥ÆäÀÌÁö¸¦ ±¸¼ºÇÏ°Ô µÇ¸é ±âº»ÀûÀ¸·Î °¡Áú ¼ö ÀÖ´Â header, menu, body, sidebar, footer·Î ±¸¼ºµÇ´Â ÆäÀÌÁö¸¦ °¡Áú ¼ö ÀÖµµ·Ï ¼³Á¤ÇÏÀÚ.
¢º ¼³Á¤ÆÄÀÏÀÇ ·Îµù ÀÚ. À§Ã³·³ ¼³Á¤À» Çسõ°í »ç¿ëÇÑ´Ù°í °¡Á¤À» ÇßÀ» °æ¿ì ¾î´À ½ÃÁ¡¿¡ Àú·¯ÇÑ ¼³Á¤ÆÄÀÏÀ» ·Îµù½Ãų °ÍÀΰ¡? web.xml°ú °°Àº °³³äÀ̶ó°í »ý°¢ÇÏÀÚ. Áï ¿£ÁøÀº request°¡ µé¾î¿À´Â½ÃÁ¡¿¡ Àú·± ¼³Á¤À» ·ÎµùÇÏ¿© ó¸®ÇÑ´Ù¸é Áö¿¬½Ã°£ÀÌ ¸¸¸¸Ä¡ ¾ÊÀ» °ÍÀ̹ǷÎ, ÃÖÃÊ requestÀÌÀü¿¡ ¸Þ¸ð¸®¿¡ ·ÎµùµÇ¾î ÀÖ¾î¾ß ÇÑ´Ù. ±×·¸´Ù¸é ÀÌÁ¦ ¹«¾ùÀÌ ÇÊ¿äÇÑ°¡? ¼³Á¤Àº XML·Î µÇ¾î ÀÖ´Ù°í ÇÏ¿´´Ù. ÆĽ̵µ±¸..¹Ù·Î ±×°ÍÀÌ´Ù. ÀÌÀü ¾ÆƼŬÀÎ SAX, DOMÆļ­¸¦ ÀÌ¿ëÇÒ ½ÃÁ¡ÀÌ µåµð¾î ¿Â°ÍÀÌ´Ù. ¾ÆÁ÷ ¾ÈÀо¾Ò´Â°¡? ¾Æ·¡ÀÇ ±ÛÀ» Àоµµ·Ï ÇÏÀÚ. About DOM & DOM Programming with Java http://www.javapattern.info/viewArticle.do?articleId=1047519735641 About SAX & SAX programming with Java http://www.javapattern.info/viewArticle.do?articleId=1047437421002 ÀÚ. Àо¾Ò´Ù¸é À§ÀÇ ÃÖÃÊ ·ÎµùµÇ¾îÁö´Â ¼­ºí¸´À» Á¤ÀÇÇÏ¿© init()¸Þ¼Òµå¿¡ À§ÀÇ ¼³Á¤ÆÄÀϵéÀ» ·ÎµùÇÏ´Â Äڵ带 ³Ö¾îº¸µµ·Ï ÇÏÀÚ. ¾Æ±î À§ÀÇ xml¿¡¼­ startup 1¹øÀ¸·Î ¼³Á¤µÈ Ŭ·¡½º°¡ ¹«¾ùÀ̾ú´Â°¡? <servlet-name>Engine</servlet-name> <display-name>FrameworkEngine</display-name> <servlet-class>com.javapattern.framework.FrameworkEngine</servlet-class> <load-on-startup>1</load-on-startup> À§ÀÇ FrameworkEngine Ŭ·¡½º¿´´Ù. À§ÀÇ ¿£ÁøÇÙ½ÉŬ·¡½º¿¡ init()¸Þ¼Òµå¿¡ xmlÀ» ÆĽÌÇÒ ¼ö ÀÖµµ·Ï ȯ°æÀ» ÀоîµéÀÌ´Â ºÎºÐÀ» »ðÀÔÇغ¸µµ·Ï ÇÏÀÚ.


public class FrameworkEngine extends HttpServlet
{
    private ServletContext context;

    public void init()
    {
        context = getServletContext();
        try {
            URL xmlURL = context.getResource("/WEB-INF/request_config.xml");
            RequestDAO.loadXml(xmlURL);
        } catch(MalformedURLException e) {e.printStackTrace();}
    }
}
   
RequestDAO´Â ¹«¾ùÀ» ÇÏ´Â °ÍÀϱî? JAXB¿¡ ´ëÇÏ¿©´Â µé¾îº¸¾Ò´Â°¡? XMLÀÇ ÀÚ¹Ùµ¥ÀÌÅÍ ¸ÅÇÎ.. µé¾îº¸Áö ¸øÇß´Ù¸é jakarta-commonsºÎºÐÀÇ digester¿¡ ´ëÇؼ­´Â ¾Ë°í Àִ°¡? Ç®¾î¼­ ¼³¸íÇÏÀÚ¸é xmlÀÇ ¹®¼­Çü½ÄÀÌ ³ªÅ¸³ª°Ô µÇ¸é ±×°ÍÀº µ¥ÀÌÅͺ£À̽º¿Í °°Àº ±¸Á¶·Î ¼³¸íÀÌ µÇ¾î Áú ¼ö ÀÖ°í, XMLÀÇ °¢ ű׵éÀº ÀÚ¹ÙÀÇ data model object·Î º¯È¯ÀÌ °¡´ÉÇÏ´Ù. À§¿¡¼­ ¼³¸íµÇ¾ú´ø request_config.xmlÆÄÀÏÀº ¸â¹öº¯¼ö·Î private String name; private String nextJsp; private String action; private String isLogin; ¸¦ °¡Áø ÀÚ¹ÙŬ·¡½ºÆÄÀÏÀÌ µÉ ¼ö ÀÖ´Ù´Â °ÍÀÌ´Ù. RequestDAO´Â ÀÌÀü ¾ÆƼŬÀÎ XML DatabaseQuery Manager±¸ÇöÇϱâÀÇ °øÅëŬ·¡½ºÀÇ ±â´ÉÀ» °®´Â´Ù. XMLÀ» ÀÌ¿ëÇÑ Database Query Manager ±¸ÇöÇϱâ http://www.javapattern.info/viewArticle.do?articleId=1047864524403 À§ÀÇ Á¤º¸´Â request¿¡ °ü·ÃµÈ Á¤º¸¸¦ °¢°¢ ÆĽÌÇÏ¿© HashMapÀÇ ÇüÅ·ΠXMLµ¥ÀÌÅ͸¦ Java Object·Î º¯Çü½ÃŲ ÈÄ¿¡ ±× Á¤º¸¸¦ °¡Áö°í ÀÖ°Ô µÈ´Ù. ÀÚ, ±×·¯¸é Framework¿£ÁøÀÇ Äڵ带 ¸ðµÎ º¸µµ·Ï ÇÏÀÚ.

package com.javapattern.framework;

import java.io.*;
import java.net.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class FrameworkEngine extends HttpServlet
{
    private ServletContext context;

    public void init()
    {
        context = getServletContext();
        try {
            URL xmlURL = context.getResource("/WEB-INF/request_config.xml");
            RequestDAO.loadXml(xmlURL);
        } catch(MalformedURLException e) {e.printStackTrace();}
    }

    public void doProcess(HttpServletRequest req, HttpServletResponse res)
    throws ServletException, IOException
    {
        String reqName = getRequestName(req);
        trace("¡Ú¡Ú¡Ú com.javapattern.framework Engine Working Start!!! ¡Ú¡Ú¡Ú  by "+reqName);
        Request config = RequestDAO.getRequest(reqName);

        if( config == null ) {
            RequestDispatcher rd = req.getRequestDispatcher("default.view");
            rd.forward(req,res);
            return;
        }
        trace(config.toString());
        
        if(config.getAction()!=null && !config.getAction().equals(""))  {
            try {
                if( config.isLogin().equals("true") ) {
                    RequestDispatcher rd = req.getRequestDispatcher("/login.jsp");
                    rd.forward(req,res);
                    return;
                }
                if(config.getAction() != null) {
                
                    Class cl = Class.forName(config.getAction());
                    RequestAction ra = (RequestAction)cl.newInstance();
                    ra.setServletContext(context);
                    ra.perform(req);
                    ra.doEnd(req);
               
                }
            } catch(Exception e) {
                e.printStackTrace();
            }
        }
        RequestDispatcher rd = req.getRequestDispatcher(config.getNextJsp());
        rd.forward(req,res);
    }

    private static String getRequestName(HttpServletRequest request)
    {
        String uri = request.getRequestURI();
        String contextPath = request.getContextPath();

        int idx = uri.lastIndexOf(".main");
        
        return uri.substring(contextPath.length()+1,idx);
    }

    public void doGet(HttpServletRequest req, HttpServletResponse res)
    throws ServletException, IOException
    {
        doProcess(req,res);
    }

    public void doPost(HttpServletRequest req, HttpServletResponse res)
    throws ServletException, IOException
    {
        doProcess(req,res);
    }

    public void trace(String msg)
    {
        System.out.println("com.javapattern.frameworkEngine ] "+msg);	
    }	
}

   
À§ÀÇ boldü·Î ¾²¿©Áø ºÎºÐµéÀÌ ÇٽɺκÐÀÌ´Ù. ÁÖ¼Òâ¿¡ xx.mainÀ̶ó´Â ÀÔ·ÂÀÌ µé¾î¿À°Ô µÇ¸é À§ÀÇ Å¬·¡½º°¡ ÀÛµ¿µÈ´Ù°í ¼³¸íÇÏ¿´´Ù. ±×·¸´Ù¸é ±× À̸§À» ¾î¶»°Ô XMLÀÇ È¯°æÁ¤º¸¿Í ¸ÅÇÎÀ» ½Ãų °ÍÀΰ¡? µé¾î¿Â request´Â getRequestName()¸Þ¼Òµå¸¦ ÅëÇÏ¿© .mainÀ» substring()ÇÏ¿© ½ÇÁ¦ ¸ÅÇÎÀ̸§¸¸À» ¾ò¾î³»°Ô µÇ´Â ¸¸¾à viewRequestList.main¶ó´Â ¿äûÀÌ µé¾î¿À°Ô µÈ´Ù¸é À§ Ŭ·¡½º´Â .mainÀ» Á¦¿ÜÇÑ viewRequestList¶ó´Â ½ºÆ®¸µÀ» ¾ò¾î³»°Ô µÇ°í, XMLÀ» ÀÚ¹Ù·Î º¯È¯½ÃŲ Request°´Ã¼ÀÇ À̸§Áß¿¡ viewRequestList¶ó´Â °´Ã¼°¡ Á¸ÀçÇÏ´Â Áö ã¾Æ³»°Ô µÈ´Ù. ±×¿ªÇÒÀ» ÇÏ´Â ºÎºÐÀÌ Request config = RequestDAO.getRequest(reqName); ÀÌ´Ù. ÀÌ·¸°Ô Çؼ­ ã¾Æ³½ °´Ã¼°¡ ÀÖÀ» °æ¿ì ¸¸¾à ó¸®ÇؾßÇÒ action class°¡ Á¸ÀçÇÏ´ÂÁö¸¦ ã¾Æº»´Ù. Á¸ÀçÇÑ´Ù¸é ¾î¶»°Ô ÇÒ°ÍÀΰ¡? ¶Ç ±× Ŭ·¡½ºÀÇ À̸§Àº ÀϹÝÀûÀÎ ½ºÆ®¸µÀÇ ÇüÅÂÀÌ´Ù. ½ºÆ®¸µÀ» °´Ã¼·Î? ÀÚ. ÀÌÁ¦ reflectionÀ» µµÀÔÇÒ¶§°¡ µÇ¾ú´Ù. °¡Àå °£´ÜÇÑ reflectionÀ¸·Î Ŭ·¡½º °´Ã¼ÀÇ »ý¼ºÀÌ Àִµ¥ ±×°ÍÀ» ÀÌ¿ëÇغ¸µµ·Ï ÇÏÀÚ. Class cl = Class.forName(config.getAction()); RequestAction ra = (RequestAction)cl.newInstance(); ra.setServletContext(context); ra.perform(req); ra.doEnd(req); config.getAction()¸Þ¼Òµå¸¦ È£ÃâÇÏ°Ô µÇ¸é viewRequestListÀÇ request¿¡ ÇØ´çÇÏ´Â actionŬ·¡½º¸¦ ¹ÝȯÇÑ´Ù ¾î¶² Ŭ·¡½ºÀÎÁö´Â request_config.xmlÀÇ <request name="viewRequestList" nextJsp="list.view" > <action-class>temporary.RequestAdminAction</action-class> </request> temporary.RequestAdminAction·Î¼­ °´Ã¼¸¦ »ý¼ºÇÏ°Ô µÇ°í ¶óÀÌÇÁ»çÀÌŬ ¸Þ¼ÒµåÀÎ ra.setServletContext(context); ra.perform(req); ra.doEnd(req); ¸¦ È£ÃâÇϵµ·Ï Áö½ÃÇÑ´Ù. ¿©±â¼­ ÇÑ°¡Áö ÁÖÀÇÇØ¾ß ÇÒ °ÍÀº ¿ì¸®°¡ ³ª¸§´ë·ÎÀÇ RequestActionÀ̶ó´Â interface¸¦ ¼±¾ðÇÏ°í °³¹ßÀڵ鿡°Ô ÀÌ Å¬·¡½º¸¦ »ó¼Ó¹Þ¾Æ¾ß ÇÑ´Ù´Â °ÍÀ» ÁÖÁö½ÃÄѾ߸¸ ÇÑ´Ù. ¿À¹ö¶óÀ̵ùÀÇ °³³äÀ» ÀÌ¿ëÇÏ¿© ÇØ´ç Ŭ·¡½º¸¦ È£ÃâÇÏ·Á¸é ÀÌ·¯ÇÑ ¼³Á¤À» ÇʼöÀ̱⠶§¹®ÀÌ´Ù. ÀÌÇØ°¡ °¡´Â°¡? ÀÌ·¸°Ô µÇ¸é ¿äû°ú µ¿½Ã¿¡ ¿äû¿¡ ÇØ´çÇÏ´Â Business¸¦ ó¸®ÇÒ ¼ö ÀÖ´Â ±âº»ÀûÀÎ controllerÀÇ È¯°æ¼³Á¤À» º¼ ¼ö ÀÖ¾ú´Ù. ´ÙÀ½ Æí¿¡¼­´Â ½ÇÁ¦ ¿äûÀÇ ¼öÇà°ú ±× ÈÄÀÇ jsp·Î forward½ÃÄ×À»¶§ À¥ÆäÀÌÁö¸¦ ¾î¶»°Ô Á¶¸³ÇÒ °ÍÀÎÁö¿¡ ´ëÇÑ Àü·«À» ¼ö¸³Çغ¸µµ·Ï ÇÏÀÚ.
 
1
References
 
Copyright ¨Ï 2003 www.javapattern.info & www.jlook.com, an jLOOK co.,LTD