JSP directives ๋Š” container์— ๋ฐฉํ–ฅ์ด๋‚˜ ๋ช…๋ น์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. ํŠน์ • ๋ถ€๋ถ„์— ๋Œ€ํ•ด์„œ ์–ด๋–ป๊ฒŒ ์ฒ˜๋ฆฌ๋ฅผ ํ•ด์•ผ ํ•œ๋‹ค๋Š” ๊ฒƒ์„ ๋ง์ด์ฃ 

JSP directive๋Š” servlet class ์ „๋ฐ˜์— ๊ฑธ์ณ์„œ ์˜ํ–ฅ์„ ๋ฏธ์นฉ๋‹ˆ๋‹ค.  

๋ฌธ๋ฒ•์€ ์•„๋ž˜์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค. 

 

<%@ directive attribute="value" %>

Directives ๋Š” ์—ฌ๋Ÿฌ๊ฐœ์˜ ์†์„ฑ์„ ๊ฐ€์งˆ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์†์„ฑ๊ณผ ์†์„ฑ ์‚ฌ์ด๋Š” ์‰ผํ‘œ๋กœ ๊ตฌ๋ถ„์„ ํ•˜๊ณ  key-value ํŽ˜์–ด๋กœ ๊ฐ’์„ ์ง€์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. 

 @ ์™€ directive๋ช… ์‚ฌ์ด์˜ ๋นˆ์นธ ๊ทธ๋ฆฌ๊ณ  ๋งˆ์ง€๋ง‰ ์†์„ฑ๊ณผ %> ์‚ฌ์ด์˜ ๋นˆ์นธ์€ ์˜ต์…˜์ž…๋‹ˆ๋‹ค. ์žˆ์–ด๋„ ๋˜๊ณ  ์—†์–ด๋„ ๋œ๋‹ค๋Š” ๊ฑฐ์ฃ . 

 

๋””๋ ‰ํ‹ฐ๋ธŒ ํƒœ๊ทธ๋Š” ์ด ์„ธ๊ฐ€์ง€ ์ข…๋ฅ˜๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค.  

DirectiveDescription
<%@ page ... %>ํŽ˜์ด์ง€ ์ข…์†์ ์ธ ์†์„ฑ๋“ค์„ ์ •์˜ํ•ฉ๋‹ˆ๋‹ค. scripting language, error page, and buffering requirements ๊ฐ™์€ ๊ฒƒ๋“ค์„ ๋งํ•ฉ๋‹ˆ๋‹ค.
<%@ include ... %>๋กœ๋“œ๋  ๋•Œ ๋™์ ์œผ๋กœ ํŒŒ์ผ์„ includeํ•ฉ๋‹ˆ๋‹ค.
<%@ taglib ... %>ํŽ˜์ด์ง€์—์„œ ์‚ฌ์šฉ๋  ์‚ฌ์šฉ์ž์ •์˜ ์•ก์…˜์„ ํฌํ•จํ•˜๋Š” ํƒœ๊ทธ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์„ ์–ธํ•ฉ๋‹ˆ๋‹ค. 


The page Directive

page directive ๋Š” ํ˜„์žฌ JSP ํŽ˜์ด์ง€์™€ ๊ด€๋ จ๋œ ๋ช…๋ น์–ด๋“ค์„ ์ปจํ…Œ์ด๋„ˆ์— ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. ๋˜ํ•œ ํŽ˜์ด์ง€ ๋””๋ ‰ํ‹ฐ๋ธŒ๋Š” JSPํŽ˜์ด์ง€ ์•„๋ฌด๋ฐ๋‚˜ ๋„ฃ์–ด๋„ ๊ด€๊ณ„๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค. ํ•˜์ง€๋งŒ ์ผ๋ฐ˜์ ์œผ๋กœ JSPํŽ˜์ด์ง€์˜ ๊ฐ€์žฅ ์œ„์ชฝ์— ์ •์˜ํ•ฉ๋‹ˆ๋‹ค.

๊ธฐ๋ณธ๋ฌธ๋ฒ•์€ ์•„๋ž˜์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค.

<%@ page attribute="value" %>

XMLํ˜•์‹์€ ์•„๋ž˜์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค.

<jsp:directive.page attribute="value" />

Attributes ( ์†์„ฑ )

ํŽ˜์ด์ง€ ๋””๋ ‰ํ‹ฐ๋ธŒ์™€ ๊ด€๋ จ๋œ ์†์„ฑ๊ณผ ๋ชฉ์ ์€ ์•„๋ž˜์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค. 

AttributePurpose
bufferSpecifies a buffering model for the output stream.
autoFlushControls the behavior of the servlet output buffer.
contentTypeDefines the character encoding scheme.
errorPageDefines the URL of another JSP that reports on Java unchecked runtime exceptions.
isErrorPageIndicates if this JSP page is a URL specified by another JSP page's errorPage attribute.
extendsSpecifies a superclass that the generated servlet must extend
importSpecifies a list of packages or classes for use in the JSP as the Java import statement does for Java classes.
infoDefines a string that can be accessed with the servlet's getServletInfo() method.
isThreadSafeDefines the threading model for the generated servlet.
languageDefines the programming language used in the JSP page.
sessionSpecifies whether or not the JSP page participates in HTTP sessions
isELIgnoredSpecifies whether or not EL expression within the JSP page will be ignored.
isScriptingEnabledDetermines if scripting elements are allowed for use.

์†์„ฑ์— ๋Œ€ํ•œ ์ž์„ธํ•œ ๋‚ด์šฉ์€ ์ด๊ณณ์—์„œ ํ™•์ธํ•˜์‹ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. 


The include Directive:

include directive๋Š” ํŽ˜์ด์ง€๊ฐ€ ๋กœ๋“œ๋  ๋•Œ ๋™์ ์œผ๋กœ ๋‹ค๋ฅธ ํŒŒ์ผ์„ include์‹œํ‚ค๊ธฐ ์œ„ํ•ด์„œ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค. ์‰ฝ๊ฒŒ๋งํ•˜๋ฉด ๋‹ค๋ฅธ ํŽ˜์ด์ง€์— ๋”ฐ๋กœ ๊ธฐ๋Šฅ์„ ๊ตฌํ˜„ํ•ด๋†“๊ณ  ์ด๊ฒƒ์„ ํ•„์š”๋กœ ํ•˜๋Š” JSPํŽ˜์ด์ง€์—์„œ includeํ•˜์—ฌ ํ•ด๋‹น ๊ธฐ๋Šฅ์„ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด์„œ ์žˆ๋Š”๊ฒ๋‹ˆ๋‹ค. 

์—ญ์‹œ ์œ„์น˜๋Š” JSPํŽ˜์ด์ง€ ๋‚ด ์•„๋ฌด๊ณณ์—๋‚˜ ๊ฐ€์ ธ๋‹ค ๋†“์œผ์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค. 

๋ฌธ๋ฒ•์€ ์•„๋ž˜์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค. 

<%@ include file="relative url" >

file์†์„ฑ์˜ value๋กœ ๋“ค์–ด๊ฐ€๋Š” ๊ฐ’์€ ํŒŒ์ผ์˜ ์ƒ๋Œ€๊ฒฝ๋กœ๋ผ๋Š” ์ ์„ ์ฃผ์˜ํ•˜์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค.  

 

XMLํ˜•์‹์€ ์•„๋ž˜์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค.

<jsp:directive.include file="relative url" />

Example:

์˜ˆ์ œ๋ฅผ ํ•œ๋ฒˆ ๋ณผ๊นŒ์š”? ROOT ๋””๋ ‰ํ† ๋ฆฌ์— ์•„๋ž˜์ฒ˜๋Ÿผ header, footer, main JSPํŒŒ์ผ์„ ๋งŒ๋“ค์–ด ๋ด…์‹œ๋‹ค.

 

header.jsp

<%! int pageCount = 0; void addCount() { pageCount++; } %> <% addCount(); %> <html> <head> <title>The include Directive Example</title> </head> <body> <center> <h2>The include Directive Example</h2> <p>This site has been visited <%= pageCount %> times.</p> </center> <br/><br/>

footer.jsp

<br/><br/> <center> <p>Copyright ยฉ 2010</p> </center> </body> </html>

main.jsp

<%@ include file="header.jsp" %> <center> <p>Thanks for visiting my page.</p> </center> <%@ include file="footer.jsp" %>

๊ทธ๋ฆฌ๊ณ  main.jsp๋ฅผ ์›น๋ธŒ๋ผ์šฐ์ €์—์„œ ์š”์ฒญ์„ ํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋Ÿฌ๋ฉด ์•„๋ž˜์™€ ๊ฐ™์€ ๊ฒฐ๊ณผ๊ฐ€ ๋‚˜์˜ฌ๊ฒƒ์ž…๋‹ˆ๋‹ค. main.jsp์—์„œ๋Š” include๋กœ ๋‹ค๋ฅธ jspํŒŒ์ผ๋งŒ ์ถ”๊ฐ€๋ฅผ ํ–ˆ์„ ๋ฟ์ธ๋ฐ ๋ˆˆ์— ๋ณด์ด๋Š”๊ฒŒ ๋งŽ์ฃ ? include๋œ jspํŒŒ์ผ๋“ค์—์„œ ๋ฟŒ๋ฆฌ๋Š” ๊ฒฐ๊ณผ๊ฐ€ main์— ๋ชจ๋‘ ํ•ฉ์ณ์ ธ์„œ ๋‚˜์˜ค๊ฒŒ ๋˜๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค. 

The include Directive Example

This site has been visited 1 times.



Thanks for visiting my page.



Copyright ยฉ 2010

 

์ƒˆ๋กœ๊ณ ์นจํ•  ๋•Œ๋งˆ๋‹ค ๋ฐฉ๋ฌธ ์นด์šดํŠธ๊ฐ€ ์ฆ๊ฐ€ํ•˜๋Š”๊ฒŒ ๋ณด์ด์‹œ๋‚˜์š”?? ^___^ 

 


The taglib Directive:

ํƒœ๊ทธ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋Š” ์‚ฌ์šฉ์ž ์ •์˜ ํƒœ๊ทธ์ž…๋‹ˆ๋‹ค.  

taglib directive๋Š” JSPํŽ˜์ด์ง€์—์„œ ์‚ฌ์šฉ์ž ์ •์˜ ํƒœ๊ทธ๋ฅผ ์‚ฌ์šฉํ•˜๊ฒ ๋‹ค๊ณ  ์ •์˜ํ•˜๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

 

๋ฌธ๋ฒ•์€ ์•„๋ž˜์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค.

<%@ taglib uri="uri" prefix="prefixOfTag" >

XMLํ˜•์‹์€ ์•„๋ž˜์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค.

<jsp:directive.taglib uri="uri" prefix="prefixOfTag" />

Example:

์˜ˆ์ œ๋ฅผ ํ•œ๋ฒˆ ๋ด…์‹œ๋‹ค. 

 custlib tag library ๊ฐ€ hello ํƒœ๊ทธ๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ๋‹ค๊ณ  ํ•ฉ์‹œ๋‹ค. hello tag ๋ฅผ mytagโ€‹๋ผ๋Š” prefix์™€ ํ•จ๊ป˜ ์‚ฌ์šฉํ•˜๊ณ  ์‹ถ์„ ๋•Œ(  <mytag:hello> ) ๋Š” ์•„๋ž˜์ฒ˜๋Ÿผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

<%@ taglib uri="http://www.example.com/custlib" prefix="mytag" %>
<html>
<body>
<mytag:hello/>
</body>
</html>

 <mytag:hello> ๋ฅผ ํ˜ธ์ถœํ•จ์œผ๋กœ์จ hello ํƒœ๊ทธ์— ๋ฏธ๋ฆฌ ์ •์˜๋˜์–ด์žˆ๋Š” ์ฝ”๋“œ๋ฅผ ์จ๋จน์„ ์ˆ˜ ์žˆ๋Š”๊ฑฐ์ฃ .

 

๊ทธ๋Ÿผ hello ํƒœ๊ทธ๊ฐ€ ์–ด๋–ป๊ฒŒ ์ •์˜๋˜์–ด์žˆ๋Š”์ง€ ํ•œ๋ฒˆ ๋ณผ๊นŒ์š”?

 

์ง€๊ธˆ ๋ง๊ณ  ๋‹ค์Œ ํฌ์ŠคํŒ…์—์„œ ๋ณด๋„๋ก ํ•˜์ฃ . ์ƒ๊ฐ๋ณด๋‹ค ๋‚ด์šฉ์ด ๋งŽ๊ฑฐ๋“ ์š” ใ…‹ใ…‹ ์ฐธ๊ณ ๋กœ ์—ฌ๊ธฐ์„œ ์‚ฌ์šฉ๋œ hello ํƒœ๊ทธ๋ฅผ ์ปค์Šคํ…€ ํƒœ๊ทธ๋ผ๊ณ  ํ•ฉ๋‹ˆ๋‹ค.

 

 

 

๊ทธ๋Ÿผ ์ข‹์€ ํ•˜๋ฃจ ๋˜์„ธ์š” ^___^

 

 

 

Reference : http://www.tutorialspoint.com/jsp/jsp_directives.htm