Search

EL (Expression Language) - ν‘œν˜„μ–Έμ–΄

EL (Expression Language) - ν‘œν˜„μ–Έμ–΄

: JSP νŽ˜μ΄μ§€μ—μ„œ 데이터λ₯Ό 좜λ ₯ν•˜κ³  ν‘œν˜„ν•˜κΈ° μœ„ν•œ μ–Έμ–΄

λͺ©μ : JSP νŽ˜μ΄μ§€μ—μ„œ μžλ°” μ½”λ“œλ₯Ό μ΅œμ†Œν™”

기본문법

${ ν‘œν˜„μ‹ }
HTML
볡사

λ‹€μ–‘ν•œ μ˜ˆμ‹œ

1.
λ³€μˆ˜ μ°Έμ‘°
${ λ³€μˆ˜λͺ… }
HTML
볡사
2.
μ—°μ‚°
${ a + b }
HTML
볡사
3.
객체의 속성 μ°Έμ‘°
${ 객체λͺ….속성λͺ… }
HTML
볡사
4.
μ»¬λ ‰μ…˜ μš”μ†Œ μ°Έμ‘°
${ μ»¬λ ‰μ…˜λͺ…[index].속성λͺ… }
HTML
볡사
5.
논리연산
${ condition ? A : B }
HTML
볡사

EL λ‚΄μž₯객체

λ‚΄μž₯ 객체
μ‚¬μš© μ˜ˆμ‹œ
μ„€λͺ…
pageScope
${pageScope.attributeName}
ν˜„μž¬ JSP νŽ˜μ΄μ§€ μŠ€μ½”ν”„μ˜ 속성에 μ ‘κ·Όν•©λ‹ˆλ‹€.
requestScope
${requestScope.attributeName}
ν˜„μž¬ HTTP μš”μ²­ μŠ€μ½”ν”„μ˜ 속성에 μ ‘κ·Όν•©λ‹ˆλ‹€.
sessionScope
${sessionScope.attributeName}
ν˜„μž¬ μ‚¬μš©μž μ„Έμ…˜ μŠ€μ½”ν”„μ˜ 속성에 μ ‘κ·Όν•©λ‹ˆλ‹€.
applicationScope
${applicationScope.attributeName}
μ›Ή μ• ν”Œλ¦¬μΌ€μ΄μ…˜ μŠ€μ½”ν”„μ˜ 속성에 μ ‘κ·Όν•©λ‹ˆλ‹€.
param
${param.parameterName}
HTTP μš”μ²­ λ§€κ°œλ³€μˆ˜μ— μ ‘κ·Όν•©λ‹ˆλ‹€.
paramValues
${paramValues.parameterName}
HTTP μš”μ²­ λ§€κ°œλ³€μˆ˜μ˜ κ°’ λͺ©λ‘μ— μ ‘κ·Όν•©λ‹ˆλ‹€.
header
${header.headerName}
HTTP μš”μ²­ 헀더에 μ ‘κ·Όν•©λ‹ˆλ‹€.
initParam
${initParam.paramName}
μ›Ή μ• ν”Œλ¦¬μΌ€μ΄μ…˜ 초기 λ§€κ°œλ³€μˆ˜μ— μ ‘κ·Όν•©λ‹ˆλ‹€.
pageContext
주둜 ν¬μ›Œλ”©, 인클루딩, λ¦¬λ‹€μ΄λ ‰νŠΈμ™€ κ΄€λ ¨λœ μž‘μ—…μ— μ‚¬μš©λ©λ‹ˆλ‹€.
ν˜„μž¬ νŽ˜μ΄μ§€ μ»¨ν…μŠ€νŠΈμ— μ ‘κ·Όν•©λ‹ˆλ‹€.

JSP λ‚΄μž₯ 객체 vs EL λ‚΄μž₯ 객체

JSP λ‚΄μž₯ 객체
EL λ‚΄μž₯ 객체
pageContext
${pageContext}
page
-
request
${requestScope}
response
-
session
${sessionScope}
application
${applicationScope}
out
${out}
config
${pageContext.config}

ν‘œν˜„μ‹

<%= λ³€μˆ˜λͺ… %>
HTML
볡사

ν‘œν˜„μ–Έμ–΄ - EL

${ λ³€μˆ˜λͺ… }
HTML
볡사

pageContext vs μŠ€ν¬λ¦½ν‹€λ¦Ώ λ³€μˆ˜ vsΒ <c:set>Β 

λ³€μˆ˜ μ„€μ • 방법
λ²”μœ„
μ ‘κ·Ό 방법
예제
μŠ€ν¬λ¦½ν‹€λ¦Ώ λ³€μˆ˜ μ„ μ–Έ
μŠ€ν¬λ¦½ν‹€λ¦Ώ μ½”λ“œ 블둝 λ‚΄μ—μ„œλ§Œ 유효
EL 둜 μ ‘κ·Ό λΆˆκ°€
<% int num1 = 10; %>
pageContext λ³€μˆ˜ μ„€μ •
νŽ˜μ΄μ§€ λ²”μœ„ (ν•΄λ‹Ή JSP νŽ˜μ΄μ§€ λ‚΄μ—μ„œλ§Œ 유효)
EL 둜 μ ‘κ·Ό κ°€λŠ₯
<% pageContext.setAttribute("num1", 10); %> ${num1}
<c:set>Β νƒœκ·Έ λ³€μˆ˜ μ„€μ •
기본적으둜 νŽ˜μ΄μ§€ λ²”μœ„ (scope 속성을 μ‚¬μš©ν•˜μ—¬ λ‹€λ₯Έ λ²”μœ„λ‘œ μ„€μ • κ°€λŠ₯)
EL 둜 μ ‘κ·Ό κ°€λŠ₯
<c:set var="num1" value="10" /> ${num1}