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°³¹ß¹æ¹ý(3)-View page Composing
 
À̹ø Æí¿¡¼­´Â FrameworkEngine¿¡¼­ forwardµÇ¾îÁø layout¿¡¼­ ¾î¶² ¹æ½ÄÀ¸·Î È­¸éÀ» composingÇÒ ¼ö ÀÖ´Â Áö¿¡ ´ëÇÑ ¹æ¾ÈÀ» ³íÀÇÇϵµ·Ï ÇÑ´Ù. ( 2003/04/07 ) 606
Written by ienvyou - ÃÖÁö¿õ
1 of 1
 

ÀÚ, Àú¹ø ±Û±îÁö´Â ¿£ÁøÀÇ ±¸¼º¿¡ ´ëÇÏ¿© ¾Ë¾Æº¸¾Ò´Ù. ¾î¶»°Ô ¶óÀÌÇÁ»çÀÌŬÀÇ È帧À» Ÿ¸ç ¾î¶°ÇÑ 
¹æ¹ýÀ¸·Î ¾ÖÇø®ÄÉÀ̼ÇÀÌ reflection¿¡ ÀÇÇÏ¿© 󸮵ǾîÁö´Â Áö¸¦ º¼¼ö ÀÖ¾ú´Ù.

¾ÆÁ÷ ÀоÁö ¾Ê¾Ò´Â°¡? ±×·³ ¾Æ·¡ÀÇ ±ÛµéÀ» ¸ÕÀú ÀÐ°í ¿À±â ¹Ù¶õ´Ù.

Web Application Framework°³¹ß¹æ¹ý(1)-FrameworkÀÇ °³¿ä 
http://www.javapattern.info/viewArticle.do?articleId=1048168663754

Web Application Framework°³¹ß¹æ¹ý(2)-LifeCycle,Controller 
http://www.javapattern.info/viewArticle.do?articleId=1048479655248

ÀÌÀü±Û¿¡¼­´Â frameworkÀÌ ¹«¾ùÀ̸ç, ±×·¯ÇÑ ÇÁ·¹ÀÓ¿÷µéÀº ¾î¶°ÇÑ ¶óÀÌÇÁ »çÀÌŬÀ» Ÿ°Ô µÇ´Â°ÍÀÎÁö
ControlÀº ¾î¶»°Ô 󸮸¦ ÇؾßÇÏ´ÂÁö¿¡ ´ëÇÏ¿© ¼³¸íÀ» ÇÑ °ÍÀÌ´Ù.
ReflectionÁß½ÉÀÇ »ç»óÀ¸·Î¼­ ±ÔÄ¢ÀÌ Á¤ÇØÁö°Ô µÇ¸é ÀϹÝÀÇ °³¹ß¹æ½ÄÀº ÀÌ¹Ì ÇÁ·¹ÀÓ¿÷»ó¿¡¼­
Á¤ÀÇÇسõÀº ÀÎÅÍÆäÀ̽º¸¦ ÅëÇÏ¿© ÀçÁ¤ÀÇÇÑ performÀ̶õ ¸Þ¼Òµå·Î controlÀ» ÇÒ ¼ö ÀÖ´Ù¶ó°í À̾߱âÇß´Ù.

ÀÚ, ±×·¯¸é request¸¦ ¹Þ¾Æ¼­ business logicÀ» ó¸®ÇÑ ÈÄ ¿ì¸®´Â ¾î¶»°Ô È­¸éÁ¶¸³À» ÀÌ·ç¾î¾ß ÇÒ °ÍÀΰ¡?
º¸Åë ÃʱâÀÇ ¼­ºí¸´¿¡¼­´Â PrintWriterÀÇ ³»¿ëÀ» ÀÌ¿ëÇÏ¿© Ãâ·ÂÀ» Çϵµ·Ï Çß¾ú´Âµ¥ pw.println()À¸·Î´Â 
È­¸éÀÌ º¹ÀâÇØÁú °æ¿ì »ó´çÇÑ À¯Áöº¸¼öÀÇ ¹®Á¦°¡ ¹ß»ýÀ» ÇÏ°Ô µÇ¾ú°í ÀÌ·Î ÀÎÇØ jspÆÄÀÏ·ÎÀÇ ÀüÀÌ°¡
°¡´ÉÇϵµ·Ï ¸Þ¼Òµå°¡ °í¾ÈµÇ¾îÁ®¾ß Çߴµ¥ ±×°ÍÀÌ ¹Ù·Î RequestDispatcherŬ·¡½ºÀÇ include(), forward()°¡
±×°ÍÀÌ´Ù.

ÀÌ·¯ÇÑ ¸Þ¼ÒµåÀÇ Á¦°øÀ¸·Î ½¬¿î jsp·ÎÀÇ º¯È¯ÀÌ °¡´ÉÇÏ°Ô µÇ¾úÀ¸¸ç, request¶ó´Â °´Ã¼¿¡ business logic¿¡¼­
¹ÝȯµÈ objectµéÀ» setting½Ãų ¼ö ÀÖ´Â ±â´ÉÀ» Á¦°øÇÔÀ¸·Î¼­ servlet°ú jsp°£ÀÇ ½¬¿î °´Ã¼ÀÇ À̵¿À» ÀÌ·ç¾î³»°Ô
ÇÏ¿´´Ù.

servletÃø¿¡¼­´Â 
    request.setAttribute("name", valueObject);
    RequestDispatcher rd = request.getRequestDispatcher("target");
    rd.forward(request,response);
ÀÇ ÇüÅ·ΠtargetÀ» È£ÃâÇÏ°Ô µÇ¸ç

jspÃø¿¡¼­´Â

<jsp:useBean id="name" class="value object type class" scope="request"/>
or
value object type class xx = request.getAttribute("name");

µîÀÇ ÇüÅ·Π¹ÞÀ» ¼ö ÀÖ´Ù´Â °É ¾Ë¾Æ¾ß ÇÑ´Ù.


ÀÚ, ÀÌÁ¦ business controlºÎºÐÀ» engine¿¡¼­ ó¸®ÇÑ ÈÄ ¾î¶»°Ô view page¸¦ ÇÒ °ÍÀΰ¡¿¡ ´ëÇÑ Àü·«À» ¼¼¿öº¸¾Æ¾ß ÇÒ °ÍÀε¥ ÀÌÀü ½Ã°£¿¡ ¾î¶»°Ô ¼³Á¤À» Çß¾ú´ÂÁö¸¦ ´Ù½Ã Çѹø Àû¾îº¸ÀÚ web.xml¿¡¼­ È®ÀåÀÚ view°¡ µé¾î¿À°Ô µÇ¸é ÀÚµ¿À¸·Î com.javapattern.framework.composer.FrameworkComposerŬ·¡½º°¡ µ¿ÀÛÀÌ µÇµµ·Ï ¹Ý¿µ½ÃÄÑ ³õ¾Ò´Ù. Composer¿¡¼­´Â µé¾î¿À´Â request¸¦ Àоîµé¿© ÀÚ½ÅÀÌ º¸¿©Áà¾ß ÇÒ ÆäÀÌÁö¿¡ ´ëÇÑ Á¤º¸¸¦ ÀÌ¿ëÇÏ¿© °¢°¢ÀÇ jspÆÄÀϵéÀ» ÇϳªÀÇ ÅÛÇø´À» ÀÌ¿ëÇÏ¿© ºê¶ó¿ìÁ®¿¡ º¸¿©Áú ¼ö ÀÖµµ·Ï ¸¸µé¾î³»°Ô ÇÏ¸é µÉ°ÍÀε¥ ÂüÁ¶xmlÀº webpage_config.xmlÀ̶õ ÆÄÀϸíÀ¸·Î ¾Æ·¡¿Í °°´Ù. ¸¸¾à À̱ÛÀ» Àд ´ç½ÅÀÌ struts tiles¿¡ Àͼ÷ÇØÁø °³¹ßÀÚ¶ó¸é ½±°Ô Á¢ÇÒ ¼ö ÀÖ´Â ³»¿ëÀÌ´Ù. ÂüÁ¶ : 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·Î ±¸¼ºµÇ´Â ÆäÀÌÁö¸¦ °¡Áú ¼ö ÀÖµµ·Ï ¼³Á¤ÇÑ´Ù. ¿Ö À§¿Í °°ÀÌ ¼³Á¤À» Çߴ°¡? º¸ÅëÀÇ À¥ÆäÀÌÁö¸¦ ¸¸µé°Ô µÇ¸é ´ëºÎºÐ 5°³ÀÇ ¿µ¿ªÀ» ÁÖ·Î ÀÌ·ç°Ô µÇ´Â°Ô °¡Àå ºó¹øÇÏ°Ô »ç¿ëÀÌ µÇ´Â ÆäÀÌÁö´Â »ó´ÜÀÇ headerºÎºÐ°ú ÇÏ´ÜÀÇ footerºÎºÐÀ¸·Î ³ª´©¾î Áö°Ô µÈ´Ù. ±×·¯ÇÑ ºÎºÐÀ» ±âÁ¸¿¡´Â °³¹ß½Ã¿¡ º¸Åë <@ include file="xx.jsp" > ¶Ç´Â <jsp:include page="xx.jsp"/> µîÀ¸·Î ó¸®ÇßÀ» °ÍÀÌ´Ù. ÇÏÁö¸¸ Àß »ý°¢Çغ¸ÀÚ. ¸Å ÆäÀÌÁö¸¦ Á¶¸³ÇÒ ¶§¸¶´Ù copy-paste¸¦ ¶Ç ÇÒ°ÍÀΰ¡? º¸Åë ±ÍÂúÀº ÀÏÀÌ ¾Æ´Ï´Ù. ±×·¸´Ù¸é ¾îÂî ¸¸µé¾î º¼±î³ª? controlleró·³ ÆäÀÌÁöµµ Áß¾ÓÁýÁßÀûÀÎ ÇüŸ¦ ÀÌ¿ëÇÑ controlºñ½ÁÇÑ jsp¸¦ ¸¸µé¾îº¸¸é ¾î¶³±î? Èì.. ±¦ÂúÀº ¹æ¹ýÀÏ °Í °°´Ù. Áï template jsp¸¦ ÀÌ¿ëÇÏ¿© Å« °ñ°ÝÀ» ÀâÀº ÈÄ °¢ ¿µ¿ª¿¡ ¹èÄ¡µÇ¾îÁú ÆäÀÌÁöµéÀ» ¹«½¼ ÁþÀ» Çؼ­µçÁö Æ÷ÇÔ½ÃÅ°¸é µÉ±î? ÀÚ. È­¸éÀ» ¾Æ·¡Ã³·³ Çѹø ¸¸µé¾îº¸´Â »À´ë¸¦ Àâ¾Æº¸µµ·Ï ÇÏÀÚ. ÀüüÀÇ ±×¸²Àº ÃÑ 5°³ÀÇ ¿µ¿ªÀ¸·Î ³ª´µ¾îÁüÀ» º¼ ¼ö Àִµ¥ header, menu, body, sidebar, footerÀÇ ±¸¼ºÀÌ´Ù. ÀϹÝÀûÀÎ À¥À» ¸¸µé°Ô µÇ¸é °¡Àå dynamicÇÏ°Ô ¹Ù²î´Â ºÎºÐÀÌ bodyºÎºÐÀÌ´Ù. Áï °³¹ßÀÚ¿¡°Ô ÀÌ·¸°Ô ÁÖ¹®ÇÏÀÚ. ´ç½ÅÀº body¸¦ º¸ÀÌ°Ô ÇÒ ¼ö ÀÖµµ·Ï ÁßÁ¡ÀûÀ¸·Î ÄÚµùÀ» ÇϽÿÀ! ¶ó°í ¸»ÀÌ´Ù. À§ÀÇ xmlÆÄÀÏ¿¡¼­ Á¶±Ý À¯½ÉÈ÷ º¸¾Æ¾ß ÇÒ ºÎºÐÀÌ ÀÖ´Ù. ¸¸¾à ÀÌ·± °æ¿ì°¡ »ý°å´Ù°í °¡Á¤À» ÇÏÀÚ. ¾î¶² ÆäÀÌÁö¸¦ bodyºÎºÐÀ» Á¶¸³ÇÏ¿© ¸¸µéµÇ sidebar¿µ¿ªÀÌ ºÒÇÊ¿äÇÑ °æ¿ì´Â ¾î¶»°Ô ÇÒ°ÍÀΰ¡? ¿ø·¡ »À´ë´Â 5ºÎºÐÀ¸·Î ³ª´µ°í PLÀ̶õ »ç¶÷¿Ð "´Ù¸¥ Áþ ÇÏ¸é ´Ù Á׿©¹ö¸±²¨¾ß, ¹«Á¶°Ç 5°³¿µ¿ªÀ¸·Î ÇØ"¶ó°í ÇÏ¸é ´ëü ¾î¶² ³ðÀ» ¾ø¾Ö¹ö·Á¾ß ÇÒ±î? ^^ °í¹ÎµÈ´Ù. ³» »ý°¢¿£ PLÀ̶õ ³ðÀ» ¾ø¾Ö¾ß ÇÒ°Í °°´Ù. À¯¿¬ÇÏÁö ¸øÇÑ ±¸Á¶.. À§ÀÇ 5°³¶ó°í ÇÑÁ¤Áö¾î³õÀº °Í ÀÚüºÎÅÍ°¡ ¹ß»óÀÌ ¾ÈÁÁ´Ù. ³î»õ°°À¸¸é ÀÌ·¸°Ô ¹°¾îº¸°Ú´Ù. "¾ÆÀú¾¾~! ½ºÅ²¸ô¶ó¿ä? ½ºÅ²?" ¹Ù¸£´Â ½ºÅ²ÀÌ ¾Æ´Ï¶ó ȯ°æ½ºÅ²¸»ÀÌ´Ù. ¸»±×´ë·Î °Ñ¸ð¾ç ²Ù¸çÁÖ´Â ²®µ¥±â¸¦ ÁöĪÇÏ´Â °ÍÀÌ´Ù. <layout>/template.jsp</layout> À§ÀÇ layoutÁ¤º¸°¡ ¹Ù·Î skinÀÇ ÇüÅÂÀÌ´Ù. Struts tiles¿¡¼­ ¾ÆÁÖ Àß Ç¥ÇöÇÏ°í ÀÖ´Ù. °Å±â¿¡´Â ¿©±â¼­ ¾²´Â ±âº»ÀûÀÎ °Í ¸»°íµµ extends°³³ä±îÁö È®Àå½ÃÄѼ­ »ç¿ëÇϹǷΠ¸¸µç »ç¶÷ÀÌ ¸Ó¸®°¡ Á» ¾ÆÆÍÀ¸¸®¶ó~ °¢¼³ÇÏ°í ÀÌ·¸°Ô layoutÀ» ±¸¼ºÇÏ¿© È­¸éÀ» º¸¿©ÁØ´Ù°í °¡Á¤À» ÇßÀ»¶§ È®ÀåÀÚ .view·Î µé¾î¿À´Â request¸¦ Composer´Â ¾î¶»°Ô ¸¸µé¾î³¾±î? Çѹø Äڵ带 º¸µµ·Ï ÇÏÀÚ.

package com.javapattern.framework.composer;

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

public class FrameworkComposer extends HttpServlet
{
    protected ServletContext context;

    public void init()
    {
        this.context = getServletContext();

        try {
            URL webpageXml = context.getResource("/WEB-INF/webpage_config.xml");
            PageConfigController.init(webpageXml);
        } catch(Exception e) { e.printStackTrace(); }	
    }

    public void execute(HttpServletRequest req, HttpServletResponse res)
    throws IOException, ServletException
    {
        String reqName = getPageName(req);
        trace("com.javapattern.framework Composer by "+reqName);
        
        PageConfig page = PageConfigController.getPageConfig(reqName);
        trace(page.toString());
        
        req.setAttribute("webpage",page);
        if( page.getLayout() == null ) page.setLayout("/template.jsp");
        RequestDispatcher rd = req.getRequestDispatcher(page.getLayout());
        rd.forward(req,res);
    }

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

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

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

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

    private void trace(String msg)
    {
        System.out.println("com.javapattern.framework Compser  ] "+msg);
    }
}
   
¿©±â¼­ Àá±ñ. À§ÄÚµåÀÇ System.out.printlnÀ¸·Î µýÁö°ÉÁö ¸»±â!!!! À§ÀÇ Äڵ忡¼­ ´«¿©°Üº¼ ºÎºÐÀº ´ç±Ù execute¸Þ¼ÒµåÀε¥ µé¾î¿À´Â request URI¸¦ ÀÌ¿ëÇÏ¿© engineó·³ È®ÀåÀÚ .view¸¦ ¾ø¾Ö°í web.xml¿¡ ¼³Á¤µÈ ȯ°æ·Îµù´ç½Ã ¸Þ¸ð¸®¿¡ ÀúÀå½ÃÄѳõÀº À§ÀÇ webpage_config.xmlÁ¤º¸¸¦ ã¾Æ³»¾î ÇØ´ç ¿äûÀÌ °¡¾ßÇÒ jspÆäÀÌÁö¸¦ webpage¶ó´Â À̸§À¸·Î ÀúÀå½ÃŲÈÄ ÇØ´ç jsp·Î forwarding½ÃÅ°´Â ÀÏÀÌ ÀüºÎÀÌ´Ù. Èì.. °£´ÜÇÏÁö ¾ÊÀº°¡? À§ÀÇ ±×¸²¿¡¼­ º» template.jspÀÇ Äڵ带 Çѹø º¸µµ·Ï ÇÏÀÚ.


<%@ taglib uri="/WEB-INF/tld/framework_composer.tld" prefix="composer" %>
<%@ page contentType="text/html;charset=euc-kr" %>
<%
	/************************************
	 *	¡Ø responseponse the Presponseentation
	 *----------------------------------*/
	response.setHeader("Cache-Control","no-cache");
	response.setHeader("Pragma","no-cache");
%>
<HTML>
<HEAD>
<TITLE><composer:insert parameter="title"/></TITLE>
<LINK REL="stylesheet" HREF="/css/common.css" TYPE="text/css">
</HEAD>
<BODY leftmargin="0" topmargin="0">
<TABLE BORDER='0' CELLSPACING='0' CELLPADDING='0' WIDTH='100%' HEIGHT='768'>
<TR>
	<TD valign=top colspan=3><composer:insert parameter="header"/></TD>
</TR>
<TR>
	<TD valign=top width="20%"><composer:insert parameter="menu"/></TD>
	<TD valign=top><composer:insert parameter="body"/></TD>
	<TD valign=top width="10%"><composer:insert parameter="sidebar"/></TD>
</TR>
<TR>
	<TD valign=top colspan=3><composer:insert parameter="footer"/></TD>
</TR>
</TABLE>
</BODY>
</HTML>


  
À§ÀÇ Äڵ忡¼­´Â composer¶ó´Â ű׸¦ ¸¸³¯ °æ¿ì parameter°ªÀ» ÀÔ·ÂÇÏ°Ô µÈ´Ù. ´«Ä¡ºü¸¥ ´ç½ÅÀ̶ó¸é paramterÀÇ value°ªÀÌ ¹«¾ùÀΰ¡¸¦ ÁöĪÇÏ°í ÀÖÀ½À» ¾Ë ¼ö ÀÖÀ» °ÍÀÌ´Ù. webpage_config.xmlÀÇ tag°¡ ¸Â´Â°¡? °Å±â¿¡ ¼³Á¤µÈ °ªÀ» È®ÀÎÇغ¸ÀÚ. °á±¹ À§ÀÇ ÄÚµåÀÇ ÇÙ½ÉÀº ¸ðµÎ Tag library°¡ ó¸®ÇÏ°í ÀÖÀ½À» ÁÖÁöÇÏÀÚ. 1. FrameworkComposer¿¡¼­ ¿äûÀÌ µé¾î¿Â request URI(xx.view¶ó´Â È®ÀåÀÚ¸¦ °¡Áø)¸¦ Çؼ®ÇÏ¿© request.setAttribute()·Î ÇØ´ç layout jsp¸¦ ¿äûÇÑ´Ù 2. layout jsp´Â È­¸é¿¡ ´ëÇÑ ±âº»°ñ°ÝÀ» °¡Áö¸ç composer:insert¶ó´Â tag library¸¦ ÅëÇÏ¿© parameter¸¦ ó¸®ÇÑ´Ù. 3. tag library°´Ã¼´Â FrameworkComposer¿¡¼­ ¼¼ÆÃÇÑ webpagesÀÇ Á¤º¸¸¦ request°´Ã¼·ÎºÎÅÍ ÀоîµéÀÎÈÄ ¼³Á¤°ªÀÌ ÀÌ¿ëÇÏ¿© pageContext¿¡ Ãâ·ÂÇϵµ·Ï ÇÑ´Ù. 4. ¼º°øÀûÀ¸·Î È­¸éÀÌ »Ñ·ÁÁø´Ù. À§ÀÇ ³»¿ëÀÌ view composerÀÇ ÀüüÀûÀÎ È帧À» ±Û·Î¼­ Ç¥ÇöÇÑ °ÍÀÌ´Ù. tag libraryÀÇ ÇÙ½É Äڵ带 º¸µµ·Ï ÇÏÀÚ.



    public int doStartTag()
    throws JspTagException 
    {
        try {
            JspWriter out = pageContext.getOut();
            out.flush();
        } catch(Exception e) {e.printStackTrace();}
        
        ServletRequest request = pageContext.getRequest();
        webpage = (PageConfig)request.getAttribute("webpage");
        if( (webpage!=null) && (parameter!=null) ) {
            try {
                if( (parameter!=null) && !parameter.equals("title")) {
                    page = webpage.getPage(parameter);
                }
            } catch(Exception e) {
                stop=true;
            }
        }
        return SKIP_BODY;
    }

    public int doEndTag()
    throws JspTagException
    {
        if(stop) return EVAL_PAGE;
        try {
            if( (parameter!=null) && parameter.equals("title") ) {
                JspWriter out = pageContext.getOut();
                out.print(webpage.getTitle());
            } else if(webpage!=null) {
                ServletRequest request = pageContext.getRequest();
                ServletResponse response = pageContext.getResponse();
                RequestDispatcher rd = request.getRequestDispatcher(page.getUrl());
                try {
                    rd.include(request,response);
                } catch(Exception th) { 
                    th.printStackTrace();
                    JspWriter out = pageContext.getOut();
                    out.println("<font size=+4 color=red>Error:</font><br>");
                    out.println("Definition for webpage \"");
                    out.println(" not found.<br>");
                    out.println("Check the webpages.xml file.[InsertPageTag]");
                    out.flush();
                }
            }
        } catch(Exception e) {
            e.printStackTrace();
            throw new JspTagException(e.getClass().getName()+
                " ] "+e.getMessage());	
        }
        return EVAL_PAGE;
    }
  
doStartTag()¿¡¼­´Â ÀÌ¹Ì FrameworkComposer¿¡¼­ request¿¡ ¼¼ÆÃÇسõÀº webpage¸¦ ¾ò¾î¿Â´Ù webpage = (PageConfig)request.getAttribute("webpage"); PageConfig°´Ã¼°¡ ¾ò¾îÁö¸é ±× ¾È¿¡´Â °¢°¢ÀÇ ¿µ¿ªÀÇ Á¤º¸°¡ µé¾îÀÖ´Â value°ªµéÀ» »Ì¾Æ³¾¼ö ÀÖ°Ô µÇ´Âµ¥ <compser:insert parameter="footer"/>¸¦ ¸¸³ª°Ô µÇ¸é PageConfig°´Ã¼¿¡¼­ footer¿¡ ÇØ´çÇÏ´Â webpageÁ¤º¸¸¦ ã¾Æ³»·Á ÇÑ´Ù. ¸¸¾à Á¸ÀçÇÏ°Ô µÈ´Ù¸é ÇØ´çÇÏ´Â URLÀ» RequestDispatcher rd = request.getRequestDispatcher(page.getUrl()); ÀÇ ÇüÅ·Πdispatch½Ãų Áغñ¸¦ ÇÏ¿© include¸¦ ½ÇÇàÇϵµ·Ï ÇÑ´Ù. ¿©±â¼­ ÁÖÀÇÇÒ Á¡Àº ÀÌ¹Ì layoutÀÇ ÇüÅ·ΠforwardµÇ¾ú°í ÇØ´ç parameter´Â ÇÑ ÆäÀÌÁöÀÇ ÇÑ¿µ¿ªÀ̱⠶§¹®¿¡ ´Ù½Ã forward½ÃÅ°¸é ¾ÈµÈ´Ù´Â °ÍÀÌ´Ù. µû¶ó¼­ rd.include(request, response)¸¦ ÅëÇÏ¿© ÇØ´ç À§Ä¡¿¡ »ðÀԵǵµ·Ï ÇÏ¸é ±×¸¸ÀÎ °ÍÀÌ´Ù. Á¶±Ý ÀÌÇØ°¡ µÇ´Â°¡? (ÀÌÇØ°¡ ¾ÈµÇ¸é TagLib, RequestDispatcher¸¦ ÀÛµ¿¹æ½ÄÀ» ´õ °øºÎÇØ¾ß ÇÒ °ÍÀÌ´Ù) ÀÚ, ÀÌ·¸°Ô À¥ÆäÀÌÁö¸¦ Á¶¸³ÇÒ ¼ö ÀÖ´Â ¹æ¹ý¿¡ ´ëÇÏ¿© ¾Ë¾Æ º¸¾Ò°í ´ÙÀ½ ½Ã°£¿¡´Â ½ÇÁ¦ ÇÁ·¹ÀÓ¿÷¼Ò½º¸¦ Àüü °ø°³ÇÑ ÈÄ weblogic6.1(7.0Àº ±Ç°íÇÏÁö ¾Ê´Â´Ù)À» ±âÁØÀ¸·Î ¼³Ä¡ ¹× Å×½ºÆ®¿Í °³¹ß ¹× ½ÇÇà¹æ¹ýÀ» ¼³¸íÇϵµ·Ï ÇÏ°Ú´Ù. °ÇÅõ¸¦ ºó´Ù.
 
1
References
 
Copyright ¨Ï 2003 www.javapattern.info & www.jlook.com, an jLOOK co.,LTD