MapleStory Finger Point

๐ŸŸค JAVA/๐ŸŸค JSP

[JSP] ํ‘œํ˜„ ์–ธ์–ด (Expression Language) :: EL

HYEJU01 2024. 8. 24. 00:58

 

 

[ EL  (Expression Language) ]

์ž๋ฐ”์ฝ”๋“œ๋ฅผ ํ‘œํ˜„์‹์„ ๋Œ€์ฒดํ•  ์ˆ˜ ์žˆ๋‹ค (๋ณต์žกํ•œ ์ฝ”๋“œ๋ฅผ ๊ฐ„๋‹จํ•˜๊ฒŒ ํ•ด์คŒ)

JSP ์Šคํฌ๋ฆฝํŠธ ์š”์†Œ๋ฅผ ๋ณด์™„ํ•˜๋Š” ์—ญํ• ์„ ํ•œ๋‹ค.

 

 

  • JSP์—์„œ ์ €์žฅ๊ฐ์ฒด๋ฅผ ์ถœ๋ ฅํ• ๋•Œ ์Šคํฌ๋ฆฝํŒ…์„ ์ „ํ˜€ ์“ฐ์ง€ ์•Š์„ ์ˆ˜ ์žˆ๋Š” ๊ธฐ์ˆ 
  • ์ผ์ข…์˜ ์Šคํฌ๋ฆฝํŠธ ์–ธ์–ด๋กœ ์ž๋ฃŒ ํƒ€์ž…, ์ˆ˜์น˜ ์—ฐ์‚ฐ์ž, ๋…ผ๋ฆฌ ์—ฐ์‚ฐ์ž, ๋น„๊ต ์—ฐ์‚ฐ์ž ๋“ฑ์„ ์ œ๊ณตํ•˜๋ฉฐ ํ‘œํ˜„์‹์„ ๋Œ€์ฒดํ•  ์ˆ˜ ์žˆ ์Šต๋‹ˆ๋‹ค.
  • <% value>  ------->   ${value} ๋กœ ์‚ฌ์šฉ๊ฐ€๋Šฅ

 

 

 

[ EL ๋‚ด์žฅ ๊ฐ์ฒด ]

 

<%= 1 + 2 %>
${ 1 + 2 }
${ 1 > 2 }
${ 2 == 2 }
${ 2 == 1 ? '๊ฐ™์Œ' : '๋‹ค๋ฆ„' }
${1 < 2 && 2 < 3} 
${1 < 2 || 2 < 3} 
${ 'ํ™๊ธธ๋™' == 'ํ™๊ธธ๋™' } 
${!false}
+ ์ง๊ด€์  ์—ฐ์‚ฐ์ž๋„ ์ œ๊ณต
${'ํ™๊ธธ๋™' eq 'ํ™๊ธธ๋™'}
${1<2 and 2<3} 
${1<2 or 2<3}
${not false}



 

[EL :  requestScope ]

<% request.getPara~("name")
request.getPara~("age") %>

${param.name}
${param.age}

//ํŒŒ๋ผ๋ฏธํ„ฐ๊ฐ’ ๊ฐ€์ ธ์˜ค๊ธฐ
//์‰ฝ๊ฒŒ ๊ฐ’์„ ๊ฐ€์ ธ์˜ฌ ์ˆ˜ ์žˆ๋‹ค.

request.setAttribute("email","aa@baer");

request.getAttribute //์—†์ด
${requestScope.email } //๋กœ ๋ฐ›์•„์˜ฌ์ˆ˜์žˆ๋”ฐ.

 

 

DepartmentDTO dto = new ()
dto.setDepartmnetID(100);
dto.setDepartmnetName('์ด๋ฆ„');

requset.setAttribute("dto",dto);
// getter ๋กœ ๋ฝ‘์•„๋‚ด์•ผํ•จ/...
${requestScope.dto.departmentId} 
// dto ์•ˆ์— ์žˆ๋Š” id ๊ฐ€์ ธ์˜ค๊ธฐ


${dto.departmentId}
${email } 
//๋ฆฌํ€˜์ŠคํŠธ์Šค์ฝ”ํ”„๋Š” ์ƒ๋žต ๊ฐ€๋Šฅ

 

 

 

 

[EL : sessionScope ]

session.setAttribute("user_id","aaa123")

${sessionScope.user_id}
${sessionScope.user_name} // ๋ฐ”๋กœ ์ฐธ์กฐ๊ฐ€๋Šฅ
${applicationScope.menu}
// sessionScope, applicationScope ์ƒ๋žต๋„ ๊ฐ€๋Šฅํ•˜์ง€๋งŒ ์ ์–ด์ฃผ๋Š” ํŽธ์ด ์ข‹๋‹ค.

//request > session > aplication ์ˆœ์œผ๋กœ
//์ด๋ฆ„๊ฐ’์„ ์ฐพ๊ธฐ ๋•Œ๋ฌธ

 

 

 

[ EL ๋žŒ๋‹ค์‹ ] 

x -> expression

(a,b) -> a > b ? true : false 

// ํŒŒ๋ผ๋ฏธํ„ฐ  -> EL์‹
// ์—ฌ๊ธฐ์„œ x๋Š” ๋žŒ๋‹ค์‹์˜ ์ž…๋ ฅ ๋งค๊ฐœ๋ณ€์ˆ˜์ด๋ฉฐ, -> ๋’ค์— ์˜ฌ ํ‘œํ˜„์‹์ด ๋žŒ๋‹ค์‹์˜ ๋ณธ๋ฌธ
 

 

์ฃผ๋กœ ํ•„ํ„ฐ๋งํ•  ๋•Œ ์‚ฌ์šฉ๋œ๋‹ค.

 

${items.stream().filter(item -> item.price > 100)}