[ EL (Expression Language) ]
์๋ฐ์ฝ๋๋ฅผ ํํ์์ ๋์ฒดํ ์ ์๋ค (๋ณต์กํ ์ฝ๋๋ฅผ ๊ฐ๋จํ๊ฒ ํด์ค)
- JSP์์ ์ ์ฅ๊ฐ์ฒด๋ฅผ ์ถ๋ ฅํ ๋ ์คํฌ๋ฆฝํ ์ ์ ํ ์ฐ์ง ์์ ์ ์๋ ๊ธฐ์
- ์ผ์ข ์ ์คํฌ๋ฆฝํธ ์ธ์ด๋ก ์๋ฃ ํ์ , ์์น ์ฐ์ฐ์, ๋ ผ๋ฆฌ ์ฐ์ฐ์, ๋น๊ต ์ฐ์ฐ์ ๋ฑ์ ์ ๊ณตํ๋ฉฐ ํํ์์ ๋์ฒดํ ์ ์ ์ต๋๋ค.
- <% value> -------> ${value} ๋ก ์ฌ์ฉ๊ฐ๋ฅ
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>์คํฌ๋ฆฝํ๋ฆฟ ์์</title>
</head>
<body>
<%
String userName = (String) request.getAttribute("userName");
int age = (Integer) request.getAttribute("age");
%>
<h1>Hello, <%= userName %>!</h1>
<p>Your age is: <%= age %></p>
<ul>
<%
List<String> fruits = (List<String>) request.getAttribute("fruits");
for (String fruit : fruits) {
%>
<li><%= fruit %></li>
<%
}
%>
</ul>
</body>
</html>
el
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>EL ์์</title>
</head>
<body>
<h1>Hello, ${userName}!</h1>
<p>Your age is: ${age}</p>
<ul>
<c:forEach var="fruit" items="${fruits}">
<li>${fruit}</li>
</c:forEach>
</ul>
</body>
</html>
[ 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 ์์ผ๋ก
//์ด๋ฆ๊ฐ์ ์ฐพ๊ธฐ ๋๋ฌธ