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

IBM developerWorks > ÀÚ¹Ù
developerWorks

JSP best practices : À¥ »çÀÌÆ®¿¡ ÄÜÅÙÆ® ¹ÝÀÔÇϱâ
¿ÜºÎ »çÀÌÆ®¿¡¼­ ÄÜÅÙÆ®¸¦ °¡Á®¿À´Â JSTL ű×

Level: Introductory

Brett McLaughlin
Author, O'Reilly and Associates
2003³â 6¿ù 17ÀÏ

Column iconÇ¥¸é»óÀ¸·Î´Â, JSTLÀÇ c:import ű״ JSPÀÇ include ¸ÞÄ¿´ÏÁòÀ» ¸ð¹æÇÑ °Íó·³ º¸ÀδÙ. ÇÏÁö¸¸ c:import (¶Ç´Â ¸ðµç JSTL ű×)¸¦ Á»´õ ÀÚ¼¼È÷ µé¿©´Ùº¸¸é Ãß°¡ÀûÀÎ ±â´ÉµéÀÌ º¸ÀÏ °ÍÀÌ´Ù.

jsp:include¿Í ¸¶Âù°¡Áö·Î c:import´Â ¸Å°³º¯¼öµéÀ» »ç¿ëÇÏ¿© ÁÖº¯ À¥ »çÀÌÆ®¿¡¼­ ÄÜÅÙÆ®¸¦ Áö´ÉÀûÀ¸·Î ¿Å±ä´Ù. ÇÏÁö¸¸ include Áö½Ã¹®°ú´Â ´Þ¸®, c:import´Â ·ÎÄà ÆÄÀÏ·ÎÀÇ Á¢±Ù¿¡ ´ëÇÑ Á¦ÇÑÀÌ ¾ø´Ù.

¹º°¡ ºüÁø °Í °°½À´Ï±î?
JSP best practices ½Ã¸®Á óÀ½ºÎÅÍ ÀÐÁö ¾Ê¾Ò´Ù¸é ÀÌ ±ÛÀÇ ³»¿ëÀ» µû¶ó°¡±â ½±Áö ¾ÊÀ» °ÍÀÌ´Ù. ´ëºÎºÐÀÇ best practices ±â¼úÀÚ·á´Â ¿¬°áµÇ¾î ÀÖÀ¸¸ç ´ëºÎºÐÀÇ ¿¹Á¦µéµµ óÀ½ºÎÅÍ Áö±Ý±îÁö °è¼Ó ÁøÈ­ÇØ¿Ô´Ù. JSP best practices ½Ã¸®Áî ¸®½ºÆ®¿¡ ½Ã°£À» ³»¾î ÂüÁ¶Çϱ⠹ٶõ´Ù.

JSTL º¯È¯
"JSTL·Î JSP ÆäÀÌÁö ¾÷µ¥ÀÌÆ®" ¸»¹Ì¿¡ jsp:include°¡ ¾Æ´Ñ c:import¸¦ »ç¿ëÇϱâ À§ÇÏ¿© À¥ »çÀÌÆ® ¸ÞÀÎÆäÀÌÁö¸¦ º¯È¯Çß´Ù. ¿äû µ¥ÀÌÅ͸¦ Àü´ÞÇÏ´Â ¸Å°³º¯¼ö¸¦ Æ÷ÇÔÇÏ°í ÀÖ¾ú±â ¶§¹®¿¡ Çì´õ ÆÄÀÏ inclusion ÄÚµå º¯°æÀº ÇÇÇß¾î¾ß Çß´Ù. (Listing 1):

Listing 1. °ÅÀÇ ´Ù º¯È¯µÈ À妽º ÆäÀÌÁö (jsp:include ¿¤¸®¸ÕÆ® ÁÖ¸ñ)

<%@ page language="java" contentType="text/html" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<html>
<head>
     <title>newInstance.com</title>
     <meta http-equiv="Content-Type" 
       content="text/html; charset=iso-8859-1" />
     <link href="/styles/default.css" rel="stylesheet" type="text/css" />
</head>

<body>

<jsp:include page="header.jsp" flush="true">
     <jsp:param name="pageTitle" value="newInstance.com"/>
     <jsp:param name="pageSlogan" value=" " />
</jsp:include>
<%@ include file="/navigation.jsp" %>
<c:import url="bookshelf.jsp" />

<c:import url="/mt-blogs/index.jsp" />

<%@ include file="/footer.jsp" %>
</body>
</html>

¸Å°³º¯¼ö ÅÂ±× º¯È¯Çϱâ
jsp:include°¡ ¾Æ´Ñ c:import¸¦ »ç¿ëÇϱâ À§ÇØ Àüü À妽º¸¦ º¯È¯ÇÒ ¶§ ¿ì¸®°¡ ÇØ¾ß ÇÒ ¸¶Áö¸· ÀÏÀº ³²¾ÆÀÖ´Â ¸Å°³º¯¼ö¸¦ Àü´ÞÇÏ´Â jsp:include ¿¤¸®¸ÕÆ®¸¦ °¡Á®¿Í¼­ ÀÌ°ÍÀÇ ÀÛµ¿À» c:import ű׷Π¿¡¹Ä·¹ÀÌÆà ÇÏ´Â °ÍÀÌ´Ù. Listing 2 ó·³, ¿ì¸®°¡ ÇØ¾ß ÇÒ ÀÏÀº jsp:param°ú c:paramÀ» ¹Ù²Ù´Â °ÍÀÌ´Ù. ¿Ö³ÄÇϸé c:paramÀº JSPÀÇ ±×°Í°ú °°Àº ±â´ÉÀ» Çϱ⠶§¹®ÀÌ´Ù.

Listing 2´Â JSTL¿¡¼­ ¿ÏÀüÈ÷ º¯È¯µÈ Listing 1ÀÇ À妽º ÆÄÀÏÀÌ´Ù:

Listing 2. JSTLÀÇ ¿ÏÀüÇÑ º¯È¯

<%@ page language="java" contentType="text/html" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<html>
<head>
     <title>newInstance.com</title>
     <meta http-equiv="Content-Type" 
       content="text/html; charset=iso-8859-1" />
     <link href="/styles/default.css" rel="stylesheet" type="text/css" />
</head>

<body>

<c:import url="header.jsp">
     <c:param name="pageTitle" value="newInstance.com"/>
     <c:param name="pageSlogan" value=" " />
</c:import>
<%@ include file="/navigation.jsp" %>
<c:import url="bookshelf.jsp" />

<c:import url="/mt-blogs/index.jsp" />

<%@ include file="/footer.jsp" %>
</body>
</html> 

JSP ÆäÀÌÁö¿¡¼­ ¸Å°³º¯¼ö¸¦ Àü´ÞÇÏ´Â °Í¿¡ ´ëÇØ Á»´õ ¾Ë°í ½Í´Ù¸é "Combine JavaBeans components and JSP technology"¸¦ ÂüÁ¶Çϱ⠹ٶõ´Ù. c:param°ú jsp:paramÀº °ÅÀÇ µ¿ÀÏÇÏ°Ô ÀÛµ¿ÇÑ´Ù´Â °ÍÀ» ±â¾ïÇÏ¸é µÈ´Ù. ÀÌÁ¦ c:importÀÇ Ã¢Á¶ÀûÀÎ È°¿ë¹ýÀ» ¾Ë¾Æº¸ÀÚ.

¿ÜºÎ ÄÜÅÙÆ® °¡Á®¿À±â
c:import¸¦ »ç¿ëÇÒ ¶§ÀÇ ÀÌÁ¡ Áß Çϳª´Â ¿ÜºÎ À¥ »çÀÌÆ®³ª À¥ ¾ÖÇø®ÄÉÀ̼ǿ¡¼­ ÄÜÅÙÆ®¸¦ °¡Á®¿Ã ¼ö ÀÖ´Ù´Â °ÍÀÌ´Ù. jsp:include¿¡ ´ëÇØ ¹è¿ï ¶§¸¦ ȸ»óÇغ¸¸é file ¾ÖÆ®¸®ºäÆ®¸¦ »ç¿ëÇÏ¿© Æ÷ÇÔ½Ãų Á¤Àû ÄÜÅÙÆ®¸¦ ÁöÁ¤Çß´Ù´Â °ÍÀ» ¾Ë ¼ö ÀÖÀ» °ÍÀÌ´Ù. file ¾ÖÆ®¸®ºäÆ®´Â À̸§ÀÌ Æ÷ÇÔÇÏ°í ÀÖ´Â °ÍÀ» ¼öÇàÇÑ´Ù: ·ÎÄà ÆÄÀÏÀÇ ÄÜÅÙÆ®¸¦ °¡Á®¿Ã ¼ö ÀÖ´Ù. c:import¿¡ ´ëÇÑ »óÀÀ ¾ÖÆ®¸®ºäÆ®´Â urlÀÌ°í ÀÌ°Í ¿ª½Ã À̸§ÀÌ ³»Æ÷ÇÏ´Â ´ë·Î ¼öÇàÇÑ´Ù: ¸ðµç URLÀ» °¡Á®¿Ã ¼ö ÀÖ´Ù. ·ÎÄà ÆÄÀÏ¿¡¼­ ÄÜÅÙÆ®¿Í ÇÔ²² »çÀÌÆ® ÆäÀÌÁö¸¦ ÆÄǽ·¹ÀÌÆà ÇÏ´Â ´ë½Å, c:import´Â ¸ðµç URL¿¡¼­ ÄÜÅÙÆ®¸¦ °¡Á®¿Ã ¼ö ÀÖ´Ù.

°£´ÜÇÑ ¿¹Á¦¸¦ µé¾îº¸°Ú´Ù. ¸¶´Ù°¡½ºÄ«¸£ ·ÎÁî¿ìµå ±âŸ ±×¸²À» ³» À¥ »çÀÌÆ®·Î °¡Á®¿À°í ½Í´Ù°í ÇÏÀÚ. À̹ÌÁö ÆÄÀÏ°ú °ü·Ã ¸µÅ©·Î ÀÌ·ç¾îÁø ÆäÀÌÁö¸¦ ±¸ÇöÇÒ ¼ö ÀÖÁö¸¸ ´Ù¸¥ »çÀÌÆ®¿¡¼­ ÄÜÅÙÆ®¸¦ °¡Á®¿À´Â ¹æ¹ýÀÌ ´õ ½±´Ù. ±×·±´ÙÀ½ ÀÚ½ÅÀÇ »çÀÌÆ® ·è¾ØÇÊ¿¡ ¸ÂÃß´Â °ÍÀÌ´Ù. (Listing 3) :

Listing 3. ¿ÜºÎ ÄÜÅÙÆ® °¡Á®¿À±â

<%@ page language="java" contentType="text/html" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<html>
<head>
     <title>newInstance.com</title>
     <meta http-equiv="Content-Type" 
       content="text/html; charset=iso-8859-1" />
     <link href="/styles/default.css" rel="stylesheet" type="text/css" />
</head>

<body>

<c:import url="header.jsp">
     <c:param name="pageTitle" 
       value="newInstance.com :: True North Guitars"/>
     <c:param name="pageSlogan" value="...building it from scratch" />
</c:import>
<%@ include file="/navigation.jsp" %>
<c:import url="bookshelf.jsp" />

<c:import 
  url="http://www.truenorthguitars.com/Clients/Richman/index.htm" />

<%@ include file="/footer.jsp" %>
</body>
</html>

ÀÌ ÄÚµå´Â ÈǸ¢ÇØ º¸ÀÌÁö¸¸ °ð¹Ù·Î ¹®Á¦°¡ ¹ß°ßµÈ´Ù. ¾î¶² À̹ÌÁöµµ ³ªÅ¸³ªÁö ¾ÊÀ¸¸ç °ü·Ã ¸µÅ©µµ ½ÇÆÐÇÑ´Ù. ¹°·Ð ¿øÀεµ ºÐ¸íÇÏ´Ù. ¿ÜºÎ ¸®¼Ò½º°¡ ÀÎÅÍÇÁ¸®ÆõDZ⠶§¹®¿¡ ÀÎÅÍÇÁ¸®ÆÃÀÌ ¾Æ¿ôDz ½ºÆ®¸²¿¡ Á÷Á¢ »ðÀԵǾú´Ù´Â °á°ú¸¦ ¾ò´Â´Ù. /images/guitar-01-24.jpg °°Àº ¿ÜºÎ À̹ÌÁö ¸µÅ©´Â ¾ø¾îÁø °ÍÀ¸·Î ³ª¿Â´Ù. ÀÌ ¹®Á¦¸¦ ÇØ°á ÇÒ À¯ÀÏÇÑ ¹æ¹ýÀº À̹ÌÁö¸¦ »çÀÌÆ®¿¡ º¹»çÇÏ´Â °ÍÀÌ´Ù. ÀÌ°ÍÀº °£´ÜÇÑ ÀÓÆ÷Æ®¿Í´Â ÀüÀûÀ¸·Î ´Ù¸£´Ù.

µû¶ó¼­ ¿ÜºÎ ÄÜÅÙÆ®¸¦ °¡Á®¿À´Â °ÍÀº ÄÜÅÙÆ®°¡ ¼ø¼öÇÏ°Ô ÅؽºÆ® ±â¹ÝÀÌ¿©¾ß¸¸ ÀÌÄ¡¿¡ ¸Â´Â´Ù. ¿¹¸¦µé¾î °ü¸®ÀÚ¸¦ À§ÇÑ »çÀÌÆ®°¡ ÀÖ´Ù°í Çغ¸ÀÚ. Çì´õ, DzÅÍ, ·è¾ØÇÊÀ» °®Ãß¾úÀ» °ÍÀÌ´Ù. »çÀÌÆ®ÀÇ ÇÑ ÆäÀÌÁö´Â Ãʱâ README ÆÄÀÏÀ» ¼³Á¤ÇÏ´Â ¹æ¹ýÀÌ ¼³¸íµÇ¾î ÀÖ¾î »ç¿ëÀڵ鿡°Ô ÀÌ »çÀÌÆ®°¡ ¾î¶»°Ô »ç¿ëµÇ¾î¾ß ÇÏ´ÂÁö¸¦ ¾Ë·ÁÁØ´Ù. ´ÙÀ½°ú °°ÀÌ FTP »çÀÌÆ®ÀÇ ÀνºÆ®·°¼ÇÀ» ÀοëÇÒ ¼ö ÀÖ´Ù:


<c:import url="ftp://ftp.oreilly.com/pub/README.ftp" />

FTP ¼­¹ö ÄÜÅÙÆ®¸¦ ÀÓÆ÷ÆÃÇÏ´Â °ÍÀº HTTP ÄÜÅÙÆ®¸¦ °¡Á®¿À´Â °Í ó·³ ½±´Ù. HTTPS¿¡ ´ëÇØ °°Àº ¸í·É¾î¸¦ »ç¿ëÇÒ ¼ö ÀÖ°í º»ÀÎ »çÀÌÆ®¿Í ¸ñÇ¥ »çÀÌÆ®°¡ ÀÌÇØÇÏ°í ¸»ÇÒ ¼ö ÀÖ´Â ÇÁ·ÎÅäÄÝÀ» »ç¿ëÇÒ ¼ö ÀÖ´Ù.

JSTL
A JSTL primer ½Ã¸®Áî:

Part 1, "The expression language" (2003³â 2¿ù)

Part 2, "Getting down to the core" (2003³â 3¿ù)

Part 3, "Presentation is everything" (2003³â 4¿ù)

Part 4, "Accessing SQL and XML content" (2003³â 5¿ù)

JSTLÀ» »ç¿ëÇÏ´Â ÀÌÀ¯
JSP ÅÂ±× º¸´Ù JSTLÀ» »ç¿ëÇÏ¸é ¿©·¯°¡Áö Å« À̵æÀ» º¼ ¼ö ÀÖ´Ù. ¿ì¼± JSTLÀº JSP ű׿ʹ ºÐ¸®µÈ ½ºÆÑÀ¸·Î Á¤ÀǵǾú´Ù. ÀÌ´Â JSP ½ºÆÑÀÌ º¯ÇÏ´õ¶óµµ JSTL űװ¡ ÀÏ°üµÉ ¼ö ÀÖ´Ù´Â °ÍÀ» º¸ÀåÇÏ´Â °ÍÀÌ´Ù. JSP ÄÁÅ×ÀÌ³Ê º¯°æ¿¡ ¿µÇâÀ» ¹ÞÀ» ¼ö ¾ø´Â ¾ÖÇø®ÄÉÀ̼ÇÀº JSTL ½ºÆÑ¿¡¼­ È¿°ú¸¦ º¼ ¼ö ÀÖ´Ù. µÑ°, JSTL ű״ ÇÙ½É JSP ű×ÀÇ ±â´Éº¸´Ù ÈξÀ ³ªÀº ±â´ÉÀ» Á¦°øÇÑ´Ù. c:import´Â ´Ù¸¥ »çÀÌÆ®¿¡¼­ URLÀ» ÀÓÆ÷Æà ÇÒ ¼ö ÀÖÀ» »Ó¸¸¾Æ´Ï¶ó jsp:include ű׿¡¼­´Â °¡´ÉÇÏÁö ¾ÊÀº º¹ÀâÇÑ ÄÜÅÙÆ®µµ ÀÓÆ÷Æ® ÇÒ ¼ö ÀÖ´Ù. ¸¶Áö¸·À¸·Î JSTLÀº °íÀ¯ÀÇ expression language(EL)À» Á¦°øÇÑ´Ù. JSTL ELÀº JSP Äڵ带 ÀÛ¼ºÇÏ´Â µ¥ ÀÖ¾î ³î¶ó¿î À¯¿¬¼ºÀ» Á¦°øÇÑ´Ù.

Âü°íÀÚ·á

¸ñ Â÷:
JSTL º¯È¯
¸Å°³º¯¼ö ÅÂ±× º¯È¯Çϱâ
¿ÜºÎ ÄÜÅÙÆ® °¡Á®¿À±â
JSTLÀ» »ç¿ëÇÏ´Â ÀÌÀ¯
Âü°í ÀÚ·á
ÇÊÀÚ ¼Ò°³
±â»ç¿¡ ´ëÇÑ Æò°¡
°ü·Ã dW ¸µÅ©:
JSP best practices series
Introduction to JavaServer Pages technology
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)

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