[Servlet] JSP - Include Directive vs. Include Action

hameeeΒ·2023λ…„ 12μ›” 6일
1

Servlet

λͺ©λ‘ 보기
12/13
post-thumbnail

πŸ“ Include Directive

  • μ •μ μœΌλ‘œ λ‹€λ₯Έ JSP νŽ˜μ΄μ§€λ₯Ό ν˜„μž¬ νŽ˜μ΄μ§€μ— μ‚½μž…ν•˜λŠ” 방식이닀.(파일 포함 방식)
  • 컴파일 μ‹œ λ‘œλ“œλ˜λ―€λ‘œ 동적 변경이 λΆˆκ°€λŠ₯ν•˜λ‹€.
  • ν•˜λ‚˜μ˜ μ„œλΈ”λ¦Ώμ΄ μƒμ„±λœλ‹€.
  • <%@ include file="#" %>

이미지 좜처

<%-- πŸ”΅ src/main/webapp/lesson03/ex01/part1.jsp -->

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<h1>Include Directive λ°©μ‹μž…λ‹ˆλ‹€.</h1>
<%-- πŸ”΅ src/main/webapp/lesson03/ex01/layout.jsp -->

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Include Directive</title>
</head>
<body>
	<header>
		<%@ include file="part1.jsp" %>
	</header>
</body>
</html>

πŸ“ Include Action

  • λ™μ μœΌλ‘œ λ‹€λ₯Έ νŽ˜μ΄μ§€μ— ν˜„μž¬ νŽ˜μ΄μ§€λ₯Ό μ‚½μž…ν•˜λŠ” 방식이닀.(νŽ˜μ΄μ§€ 포함 방식)
  • λŸ°νƒ€μž„ μ‹œ λ‘œλ“œλ˜λ―€λ‘œ 동적 변경이 κ°€λŠ₯ν•˜λ‹€.
  • 각 JSPλ§ˆλ‹€ μ„œλΈ”λ¦Ώμ΄ μƒμ„±λœλ‹€.
  • <jsp:include page="#" />

이미지 좜처

<%-- πŸ”΅ src/main/webapp/lesson03/ex02/part1.jsp -->

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<h1>Include Action λ°©μ‹μž…λ‹ˆλ‹€.</h1>
<%-- πŸ”΅ src/main/webapp/lesson03/ex02/layout.jsp -->

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Include Action</title>
</head>
<body>
	<header>
		<jsp:include page="part1.jsp" />
	</header>
</body>
</html>

πŸ“ 비ꡐ

속성Include DirectiveInclude Action
μ½”λ“œ 문법<%@ include file="#" %><jsp:include page="#" />
λ‹€λ₯Έ 이름file includepage include
μ‚½μž… 방식JSP νŽ˜μ΄μ§€ μ½”λ“œκ°€ λ‹€λ₯Έ JSP νŽ˜μ΄μ§€ μ½”λ“œμ— μ‚½μž…μ‘λ‹΅μœΌλ‘œ 받은 νŽ˜μ΄μ§€κ°€ λ‹€λ₯Έ νŽ˜μ΄μ§€μ— μ‚½μž…
좜λ ₯ 바인딩/Import정적동적
파일의 νŠΉμ„±ν¬ν•¨λœ νŽ˜μ΄μ§€κ°€ 자주 λ³€κ²½λ˜μ§€ μ•Šμ„ λ•Œ μ„ ν˜Έλ¨ν¬ν•¨λœ νŽ˜μ΄μ§€κ°€ 자주 변경될 λ•Œ μ„ ν˜Έλ¨
μƒμ„±λ˜λŠ” μ„œλΈ”λ¦Ώ μˆ˜μ—¬λŸ¬ 개의 JSP에 λŒ€ν•΄ ν•˜λ‚˜μ˜ μ„œλΈ”λ¦Ώμ΄ 생성됨각 JSP에 λŒ€ν•΄ 각각의 μ„œλΈ”λ¦Ώμ΄ 생성됨
ν¬ν•¨λ˜λŠ” 파일컴파일 μ‹œ λ‘œλ“œλ¨λŸ°νƒ€μž„ μ‹œ λ‘œλ“œλ¨
ν¬ν•¨λ˜λŠ” νŒŒμΌμ— λ³€κ²½ 사항이 μžˆμ„ κ²½μš°λ‹€μŒ 컴파일 μ‹œ λ‚˜νƒ€λ‚¨λ‹€μŒ μš”μ²­ μ‹œ λ‚˜νƒ€λ‚¨
μ‹€ν–‰ νƒ€μ΄λ°λ²ˆμ—­ μ‹œ μ‹€ν–‰λ¨μš”μ²­ μ‹œ 싀행됨
같은 μ΄λ¦„μ˜ λ³€μˆ˜ μ‚¬μš©λΆˆκ°€λŠ₯κ°€λŠ₯
μ„±λŠ₯빠름비ꡐ적 느림

πŸ“ μ£Όμ˜ν•  점

  • ν¬ν•¨ν•˜λŠ” JSP 파일, ν¬ν•¨λ˜λŠ” JSP 파일 λͺ¨λ‘ JSP νŽ˜μ΄μ§€μž„μ„ λͺ…μ‹œν•˜κΈ° μœ„ν•΄ 상단에 <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> μ½”λ“œκ°€ ν•„μš”ν•˜λ‹€.
  • ν¬ν•¨λ˜λŠ” JSP 파일 생성 μ‹œ μž‘μ„±λΌ μžˆλŠ” HTML λΌˆλŒ€λŠ” λͺ¨λ‘ μ‚­μ œ ν›„ ν•„μš”ν•œ HTML μ½”λ“œλ§Œ μž‘μ„±ν•œλ‹€.
  • μŠ€νƒ€μΌμ€ λΈŒλΌμš°μ €μ—μ„œ νŽ˜μ΄μ§€λ₯Ό λ Œλ”λ§ν•  λ•Œ μ μš©λ˜λ―€λ‘œ, Include Directive 방식, Include Action 방식 λͺ¨λ‘ ν¬ν•¨ν•˜λŠ” νŽ˜μ΄μ§€μ— μŠ€νƒ€μΌ μ½”λ“œλ₯Ό μž‘μ„±ν•˜λ©΄ 전체에 μ μš©λœλ‹€.
  • ν¬ν•¨ν•˜λŠ” νŽ˜μ΄μ§€λ‘œ μ „μ†‘λœ μš”μ²­ νŒŒλΌλ―Έν„°λŠ” ν¬ν•¨λ˜λŠ” νŽ˜μ΄μ§€μ—μ„œλ„ 읽을 수 μžˆλ‹€.
  • ν¬ν•¨λ˜λŠ” νŽ˜μ΄μ§€λ‘œ μš”μ²­μ„ 보내지 μ•ŠλŠ”λ‹€. μš”μ²­ μ‹œ ν•΄λ‹Ή νŽ˜μ΄μ§€λ‘œ μ΄λ™ν•˜λŠ”λ°, ν¬ν•¨λ˜λŠ” νŽ˜μ΄μ§€μ—λŠ” HTML λΌˆλŒ€κ°€ μ—†μœΌλ―€λ‘œ ν¬ν•¨λ˜λŠ” νŽ˜μ΄μ§€μ˜ HTML νƒœκ·Έλ§Œ λΈŒλΌμš°μ €μ— ν‘œμ‹œλ˜κΈ° λ•Œλ¬Έμ΄λ‹€.

References

πŸ”— https://www.sitesbay.com/jsp/include-directive-and-include-action
πŸ”— https://way2java.com/jsp/difference-between-jsp-include-directive-and-include-action

0개의 λŒ“κΈ€