IBM Korea Skip to main content
       IBM Ȩ    |  Á¦Ç° & ¼­ºñ½º  |  °í°´Áö¿ø & ´Ù¿î·Îµå  |  È¸¿ø°¡ÀÔ  

IBM developerWorks > ÀÚ¹Ù
developerWorks

JSP best practices : ŸÀÓ ½ºÅÆÇÁÀÇ Èû
JSP ÆäÀÌÁö¿¡ ŸÀÓ ½ºÅÆÇÁ ¸¸µé±â

Level: Introductory

Brett McLaughlin
O'Reilly and Associates
2003³â 7¿ù 1ÀÏ

Column iconJSP ÆäÀÌÁö¿¡ ŸÀÓ ½ºÅÆÇÁ¸¦ Ãß°¡ÇÏ´Â ´Ù¾çÇÑ ±â¼úÀ» °ËÅäÇÑ´Ù. ¶ÇÇÑ ÀÌ·± °£´ÜÇÑ º¯°æÀ» ÅëÇØ À¥ »çÀÌÆ®ÀÇ °¡¿ë¼ºÀ» Çâ»ó½Ãų ¼ö ÀÖ´Ù.

ŸÀÓ ½ºÅÆÇÁ(Time stamp)´Â °³ÀÎ »çÀÌÆ®³ª ÄÜÅÙÆ® À§ÁÖ »çÀÌÆ® °°Àº °£´ÜÇÑ À¥ »çÀÌÆ®¿¡ ÀϹÝÀûÀ¸·Î »ç¿ëµÈ´Ù. »ç¿ëÀÚµéÀÌ ÆäÀÌÁöÀÇ ÃÖÁ¾ ¾÷µ¥ÀÌÆ® ½ÃÁ¡À» º¼ ¼ö ÀÖ´Â ÀåÄ¡ÀÌ´Ù. °á°úÀûÀ¸·Î ÇÊ¿äÇÑ ºÎºÐÀ» º¸±â°¡ ½±´Ù. ƯÈ÷ ÀüÀÚ»ó°Å·¡ »çÀÌÆ®¿¡¼­ À¯¿ëÇÏ´Ù. JSP ÆäÀÌÁö¿¡ ŸÀÓ ½ºÅÆÇÁ¸¦ Ãß°¡ÇÔÀ¸·Î¼­ »ç¿ëÀڵ鿡°Ô Á»´õ ½¬¿î Á¢±Ù¼ºÀ» Çã¿ëÇÏ°í ƯȭµÈ »çÀÌÆ®·ÎÀÇ ±æÀ» ¿­¾îÁØ´Ù.

ŸÀÓ ½ºÅÆÇÁ Ãß°¡Çϱâ
JSP ÆäÀÌÁö¿¡ ¸¶Áö¸·À¸·Î ¼öÁ¤µÈ ³¯Â¥³ª ŸÀÓ ½ºÅÆÇÁ¸¦ ³Ö´Â °ÍÀº ´Ù¸¥ À¯ÇüÀÇ ÆäÀÌÁö¿¡ ÇÏ´Â °Í°ú ´Ù¸£Áö ¾Ê´Ù. java.io.File Ŭ·¡½º´Â lastModified ¸Þ¼Òµå¸¦ Á¦°øÇÑ´Ù. Æ®¸¯ÀÌ ÇÊ¿äÇÑ À¯ÀÏÇÑ ºÎºÐÀº JSP ÆäÀÌÁö¿¡ ´ëÇÑ File ÇÚµéÀ» À¥ ÄÜÅ×À̳ʿ¡ Àü°³½ÃÅ°´Â °ÍÀÌ´Ù. (Listing 1).

application°ú request ¸ðµÎ ¸ðµç JSP ÆäÀÌÁö°¡ ¾×¼¼½ºÇÒ ¼ö ÀÖ´Â ºôÆ®ÀÎ º¯¼ö¶ó´Â °Í¿¡ ÁÖ¸ñÇ϶ó. applicationÀº JSP ÆäÀÌÁö¿ë javax.servlet.ServletContext °´Ã¼¸¦ ±¸ÇöÇϴ Ŭ·¡½ºÀÇ ÀνºÅϽº¸¦ ³ªÅ¸³½´Ù. ÀÌ °´Ã¼´Â JSP ÆäÀÌÁöÀÇ ¼­ºí¸´ °æ·Î¸¦ ÃëÇÒ ¼ö ÀÖ°í À̷μ­ JSP ÆäÀÌÁö¿ë ¹°¸®Àû °æ·Î·Î ¹Ù²ï´Ù. ÀÌ °æ·Î´Â ±× ´ÙÀ½¿¡ File·Î ¹Ù²ï´Ù.

Listing 1. File ÇÚµéÀ» JSP·Î °¡Á®°¡±â

String jspPath = application.getRealPath(request.getServletPath());
java.io.File jspFile = new java.io.File(jspPath);

ÀÌ ¸ðµç Á¤º¸¸¦ °¡Á®´Ù°¡ ½ÇÇà½ÃÅ°·Á¸é Listing 2ÀÇ Äڵ带 »ç¿ëÇÑ´Ù:

Listing 2. Printing out a time stamp

<%
     String jspPath = application.getRealPath(request.getServletPath());
     java.io.File jspFile = new java.io.File(jspPath);
     out.println(new java.util.Date(jspFile.lastModified()));
%>

ÆÄÀÏÀÇ ¸¶Áö¸· ¼öÁ¤ ³¯Â¥°¡ °áÁ¤µÈ ÈÄ¿¡ ÀÌ°ÍÀº µ¥ÀÌÆ® °´Ã¼·Î ¹Ù²ï´Ù. ÀÌ°ÍÀÌ ½ºÅ©¸°À¸·Î Á÷Á¢°¡´Â ¾Æ¿ôDzÀÌ´Ù. ¸Å¿ì ±âº»ÀûÀÎ ÄÚµå·Î ÁÁÀº °á°ú¸¦ °¡Á®¿Ô´Ù.

Àç»ç¿ëÀÌ °¡´ÉÇÑ Å¸ÀÓ ½ºÅÆÇÁ
¹°·Ð, ¿øÇÏ´Â ÆäÀÌÁö¸¶´Ù À§¿Í °°Àº Äڵ带 ŸÀÓ ½ºÅÆÇÁ¿¡ Ãß°¡ÇÏ´Â °ÍÀº °íÅ뽺·¯¿î ÀÏÀÌ´Ù. º¸´Ù ³ªÀº ¹æ¹ýÀº ³¯Â¥¿Í ŸÀÓ ½ºÅÆÇÁ¸¦ µð½ºÇ÷¹ÀÌÇÏ´Â ÀϹÝÀûÀÎ JSP ÆäÀÌÁö¸¦ ¸¸µé¾î¼­ ¿øÇÏ´Â ¸ðµç À§Ä¡¿¡ JSP ÆäÀÌÁö¸¦ Æ÷ÇÔ½ÃÅ°´Â °ÍÀÌ´Ù. À̸¦ À§Çؼ­´Â Listing 2¸¦ timestamp.jsp·Î ÀúÀåÇÏ°í jsp:include¸¦ »ç¿ëÇÏ¿© ÇÊ¿äÇÑ °÷ ¸¶´Ù ŸÀÓ ½ºÅÆÇÁ¸¦ ¸¸µé¾î³»´Â °ÍÀÌ´Ù. Listing 3Àº JSP ŸÀÓ ½ºÅÆÇÁ¸¦ Æ÷ÇÔÇÏ°í ÀÖ´Â °£´ÜÇÑ Ç²ÅÍ(footer) ÆäÀÌÁöÀÌ´Ù:

Listing 3. ´Ù¸¥ JSP ÆäÀÌÁö¿¡ ŸÀÓ ½ºÅÆÇÁ Ãß°¡Çϱâ

<!-- Begin footer section -->
     <tr>
       <td width="91" align="left" valign="top" bgcolor="#330066"> </td>
       <td align="left" valign="top"> </td>
       <td class="footer" align="left" valign="top">
           <div align="center"><br>
           &copy; 2003 <a href="mailto:webmaster@newInstance.com">Brett 
               McLaughlin</a><br>
       Last Modified: <jsp:include page="timestamp.jsp" flush="true" />
         </div></td>
           <td align="left" valign="top"> </td>
       <td width="141" align="right" valign="top" bgcolor="#330066"> </td>
     </tr>
</table>
<!-- End footer section -->

Listing 3¿¡ Æ÷ÇÔµÈ ÆÄÀÏÀº Æ÷ÇÔµÈ Å¸ÀÓ ½ºÅÆÇÁ ÆÄÀÏÀÌ ¾Æ´Ï¶ó ºÎ¸ð JSP ÆäÀÌÁö(ÀÌ °æ¿ì footer.jsp)¸¦ º¸¿©Áشٴ °ÍÀ» ´«Ä¡Ã«À» °ÍÀÌ´Ù. ±×·¡¼­ ¸¶Áö¸·À¸·Î º¯°æµÈ ³¯Â¥¿Í ŸÀÓ ½ºÅÆÇÁ´Â timestamp.jsp°¡ ¾Æ´Ñ footer.jsp ¿¡¼­ °¡Á®¿À°Ô µÇ¾ú´Ù. ŸÀÓ ½ºÅÆÇÁ ÆÄÀÏÀº ½ÇÁ¦·Î Á¤Àû ÆÄÀÏÀ̱⠶§¹®¿¡(º¯ÇÏÁö ¾Ê´Â´Ù), ÀÌ°ÍÀº ¸Å¿ì Áß¿äÇÏ´Ù. µû¶ó¼­ ¸¶Áö¸·À¸·Î º¯°æµÈ Äõ¸®´Â footer.jsp °°Àº ÀÚµ¿ÀûÀ¸·Î ¾÷µ¥ÀÌÆ®µÈ ÆäÀÌÁö·Î °¡¾ßÇÑ´Ù.

ÇÑ ´Ü°è ´õ ±íÀÌ µé¾î°¡¼­ ´Ù¾çÇÑ ÄÜÅÙÆ® ÆäÀÌÁöµé·Î ±¸¼ºµÈ »çÀÌÆ®¸¦ »ý°¢Çغ¸ÀÚ. À̵é ÆäÀÌÁöµéÀº °¢ÀÚ ÇϳªÀÇ footer.jsp ÆäÀÌÁö¸¦ Æ÷ÇÔÇÏ°í ÀÖ´Ù. ¿©±â¿¡´Â timestamp.jsp°¡ Æ÷ÇԵǾî ÀÖ´Ù. ¸¶Áö¸·À¸·Î º¯°æµÈ ³¯Â¥°¡ ÃÖ»óÀ§ ÆäÀÌÁö¸¦ ã´Â´Ù¸é ŸÀÓ ½ºÅÆÇÁ´Â ÄÜÅÙÆ®°¡ º¯°æµÉ ¶§ º¯ÇÑ´Ù.

ŸÀÓ ½ºÅÆÇÁ Æ÷¸Ë
±âº» ³¯Â¥¿Í ŸÀÓ ½ºÅÆÇÁ ¾Æ¿ôDzÀº ºñ±³Àû ¸Å·ÂÀÌ ´úÇÏ´Ù. (Fri Mar 28 10:30:10 CST 2003). ´ÙÇàÈ÷ ¾Æ¿ôDz Æ÷¸ËÀ» Àß Á¦¾îÇÒ ¼ö ÀÖ´Â java.text.SimpleDateFormat Ŭ·¡½º¸¦ »ç¿ëÇÒ ¼ö ÀÖ´Ù. Listing 4´Â java.text.SimpleDateFormatÀÌ Ãß°¡µÈ timestamp.jspÀÌ´Ù.

Listing 4. ŸÀÓ ½ºÅÆÇÁ Æ÷¸Ë

<%
     String jspPath = 
       application.getRealPath(request.getServletPath());
     java.io.File jspFile = new java.io.File(jspPath);
     java.util.Date lastModified = 
       new java.util.Date(jspFile.lastModified());
     java.text.SimpleDateFormat fmt =
       new java.text.SimpleDateFormat("MMM dd, yyyy, K:mm a (zz)");
     out.println(fmt.format(lastModified));
%>

°á°ú ¾Æ¿ôDzÀº Mar 28, 2003, 10:30 AM (CST)ÀÌ´Ù. »ç¿ëÀÚÀÇ ÀÔÀå¿¡¼­ º¸¸é ÈξÀ ³ª¾ÆÁø ¸ð½ÀÀÌ´Ù.

WAR·Î ÀÛ¾÷Çϱâ
WAR(À¥ ¾ÆÄ«À̺ê) ÆÄÀϾȿ¡ À¥ ¾ÖÇø®ÄÉÀ̼ÇÀÇ ÀϺημ­ JSP ÆäÀÌÁö¸¦ Àü°³ÇÒ ¶§ Á¦ÇÑ ¿ä¼Ò°¡ ÀÖ´Ù. ¼­ºí¸´ ÄÜÅ×À̳ʵéÀº ÀϹÝÀûÀ¸·Î WAR ÆÄÀϵéÀ» Àӽà µð·ºÅ丮·Î È®ÀåÇÏ¿© Àӽà µð·ºÅ丮¿¡¼­ ÄÜÅÙÆ®¸¦ Á¦°øÇÏ¿© WAR ÆÄÀϵéÀ» Àü°³ÇÑ´Ù. ¹®Á¦´Â ÀÌ·¯ÇÑ »óȲ¿¡¼­ JSP ÆäÀÌÁö¿Í ¿¬µ¿ÇÑ File °´Ã¼¸¦ Æ÷ÇÔ½Ãų ¼ö ¾ø´Ù´Â °ÍÀÌ´Ù. ¿ÀÈ÷·Á Àӽà ÆÄÀÏ·Î ÇÚµéÀ» ¸¸µé¼ö¸¸ Àִµ¥ ÀÌ°ÍÀº À¥ ÄÜÅ×À̳ʰ¡ Àç½ÃÀÛÇÒ ¶§¸¶´Ù ´Ù½Ã¸¸µé¾îÁö°Ô µÈ´Ù.

¹ø°Å·ÓÁö¸¸ Àü°³µÈ ¼­¹ö¿¡¼­ WAR ÆÄÀÏÀ» Á÷Á¢ °¡Á®¿Í¾ß ÇÑ´Ù. ¼öµ¿ ÃßÃâÀÇ ºÒÆíÇÔÀº ºñ±³Àû Àû´Ù. ±×¸®°í ÀÏ´Ü ¼öÇàÇϸé ŸÀÓ ½ºÅÆÇÁ´Â Á¤»óÀûÀ¸·Î ÀÛµ¿ÇÑ´Ù.

Âü°íÀÚ·á

¸ñ Â÷:
ŸÀÓ ½ºÅÆÇÁ Ãß°¡Çϱâ
Àç»ç¿ëÀÌ °¡´ÉÇÑ Å¸ÀÓ ½ºÅÆÇÁ
ŸÀÓ ½ºÅÆÇÁ Æ÷¸Ë
WAR·Î ÀÛ¾÷Çϱâ
Âü°í ÀÚ·á
ÇÊÀÚ ¼Ò°³
±â»ç¿¡ ´ëÇÑ Æò°¡
°ü·Ã dW ¸µÅ©:
JSP best practices series
Dynamic Web-based data access using JSP and JDBC technologies
JSP taglibs: Better usability by design
Subscribe to the developerWorks newsletter
US ¿ø¹® Àбâ
Also in the Java zone:
Tutorials
Tools and products
Code and components
Articles
ÇÊÀÚ¼Ò°³
Photo of Brett McLaughlinBrett McLaughlinÀº ÇöÀç ÀÚ¹Ù ¹× °ü·Ã ±â¼úÀ» ÀÌ¿ëÇÏ¿© ¾ÖÇø®ÄÉÀÌ¼Ç ±â¹Ý±¸Á¶ ±¸ÇöÀ» Àü¹®ÀûÀ¸·Î ¼öÇàÇÏ°í ÀÖ´Ù. BrettÀº Java Apache ÇÁ·ÎÁ§Æ®ÀÎ TurbineÀÇ °øµ¿ ⸳ÀÚÀÌ´Ù.
ÀÌ ±â»ç¿¡ ´ëÇÏ¿© ¾î¶»°Ô »ý°¢ÇϽʴϱî?

Á¤¸» ÁÁ´Ù (5) ÁÁ´Ù (4) ±×Àú±×·¸´Ù (3) ¼öÁ¤º¸¿ÏÀÌ ÇÊ¿äÇÏ´Ù(2) ÇüÆí¾ø´Ù (1)

  È¸»ç¼Ò°³  |  °³ÀÎÁ¤º¸ º¸È£Á¤Ã¥  |  ¹ý·ü  |  ¹®ÀÇ