λ³Έλ¬Έ λ°”λ‘œκ°€κΈ°
JSP

[JSP] μ§€μ‹œμ–΄ (Directive)

by μ½”λ”©ν•˜λŠ” λΆ•μ–΄ 2021. 2. 9.
λ°˜μ‘ν˜•

β–Ά import 속성

μžλ°”μ—μ„œ μ‚¬μš©ν•˜λŠ” import ꡬ문과 같은 의미λ₯Ό 가지고 μžˆλŠ” μ†μ„±μœΌλ‘œ JSP νŽ˜μ΄μ§€ λ‚΄μ—μ„œ μ‚¬μš©ν•  νŒ¨ν‚€μ§€ λ˜λŠ” 클래슀λ₯Ό importν•˜λŠ”λ° μ‚¬μš©λœλ‹€.

​

​

importTest.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.util.*"%>
<html>
<head>
<meta charset="UTF-8">
<title>import 속성 ν…ŒμŠ€νŠΈ</title>
</head>
<body>
<h1>ν˜„μž¬ μ‹œκ°„μ€ <%=new SimpleDateFormat().format(new Date()) %>μž…λ‹ˆλ‹€.</h1>
</body>
</html>

 

<μ‹€ν–‰ κ²°κ³Ό>

​​

​

​

β–Ά include μ§€μ‹œμ–΄

include μ§€μ‹œμ–΄λŠ” νŠΉμ •ν•œ JSP 파일 λ˜λŠ” HTML νŒŒμΌμ„ ν•΄λ‹Ή JSP νŽ˜μ΄μ§€μ— μ‚½μž…ν•  수 μžˆλ„λ‘ ν•˜λŠ” κΈ°λŠ₯을 μ œκ³΅ν•˜λŠ” μ§€μ‹œμ–΄μ΄λ‹€. μ—¬λŸ¬ JSP νŽ˜μ΄μ§€μ—μ„œ κ³΅ν†΅λ˜λŠ” 뢀뢄이 λ§Žμ„ λ•Œ κ³΅ν†΅λ˜λŠ” 뢀뢄을 λ”°λ‘œ 파일둜 λ§Œλ“€μ–΄ include μ§€μ‹œμ–΄λ‘œ μ‚½μž…ν•˜λ©΄ 맀번 같은 λ‚΄μš©μ„ μž…λ ₯ν•˜μ§€ μ•Šκ³ λ„ κ³΅ν†΅λ˜λŠ” 뢀뢄을 κ°„λ‹¨ν•˜κ²Œ ν¬ν•¨μ‹œν‚¬ 수 μžˆλ‹€. Chapter6 μ—μ„œ μ„€λͺ…ν•  λ ˆμ΄μ•„μ›ƒ ν…œν”Œλ¦Ώ νŽ˜μ΄μ§€λ₯Ό μž‘μ„±ν•  λ•Œ 많이 쓰여지며 λ‹€μŒκ³Ό 같은 ν˜•μ‹μœΌλ‘œ μ‚¬μš©ν•œλ‹€.

이 λ•Œ ν¬ν•¨λ˜λŠ”(include λ˜λŠ”) νŒŒμΌλ“€μ€ μ‹€μ œ 컴파일 과정을 κ±°μ³μ„œ κ·Έ κ²°κ³Όκ°€ ν•΄λ‹Ή JSP νŽ˜μ΄μ§€μ— ν¬ν•¨λ˜λŠ” 것이 μ•„λ‹ˆλΌ JSP μ†ŒμŠ€ μ½”λ“œ μžμ²΄κ°€ ν•΄λ‹Ή JSP νŽ˜μ΄μ§€μ— λ³΅μ‚¬λ˜μ–΄ λ”ν•΄μ§€λ―€λ‘œ μ„œλΈ”λ¦Ώ 컴파일 과정은 includeλ˜λŠ” 파일의 κ°œμˆ˜κ°€ 아무리 λ§Žλ‹€κ³  ν•˜λ”λΌλ„ 단 ν•œ 번만 μ΄λ£¨μ–΄μ§€κ²Œ λœλ‹€.

λ˜ν•œ include μ§€μ‹œμ–΄λŠ” 쀑첩 μ‚¬μš©μ΄ κ°€λŠ₯ν•˜κΈ° λ•Œλ¬Έμ— includeλ˜λŠ” 파일 μ•ˆμ—μ„œ 또 λ‹€λ₯Έ νŒŒμΌμ„ includeν•˜μ—¬λ„ λ¬Έμ œμ—†μ΄ λ™μž‘ν•œλ‹€.

​

​

includeTest.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//w3c//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@ include file="header.jsp" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>include ν…ŒμŠ€νŠΈ</title>
</head>
<body>
<h1>includeTest.jsp νŒŒμΌμž…λ‹ˆλ‹€.</h1>
<%@ include file="footer.jsp" %>
</body>
</html>

 

 

header.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h3>header.jsp 파일의 λ‚΄μš©μ΄ λ“€μ–΄κ°€λŠ” κ³³μž…λ‹ˆλ‹€.</h3>
</body>
</html>

 

 

footer.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h3>footer.jsp 파일의 λ‚΄μš©μ΄ λ“€μ–΄κ°€λŠ” κ³³μž…λ‹ˆλ‹€.</h3>
</body>
</html>

 

<μ‹€ν–‰ κ²°κ³Ό>

 

λ°˜μ‘ν˜•

λŒ“κΈ€