EL, Expression Language는 JSP 2.0에 추가되어
<%=%> 와 같은 jsp에 쓰는 java 코드를 간결하게 사용하는 방법
EL의 연산자 기호는 다음과 같이 있다.
사용하는데 일반 연산자를 써도 상관없긴 하다.
일반 연산자 |
EL 기호 연산자 |
+, - |
+, - |
*, / |
*, div |
% |
mod |
&& |
and |
|| |
or |
! |
not |
> |
lt(less than) |
< |
gt(greater than) |
>= |
le(less or eqaul) |
<= |
ge(greater or equal) |
== |
eq(equal) |
!= |
ne(not equal) |
value == null |
empty |
EL 태그의 내장 객체
pageScope |
page영역의 객체에 접근 |
requestScope |
request영역의 객체에 접근 |
sessionScope |
session영역의 객체에 접근 |
applicationScope |
application영역의 객체에 접근 |
param |
전달된 파라미터값을 받아올 때 |
paramValues |
전달된 파라미터값을 배열로 |
header |
특정 헤더 정보를 받아올 때 |
headerValues |
특정 헤더 정보를 배열로 받아올 때 |
cookie |
${cookie.key} 형식으로 쿠키값 조회 |
initParam |
초기 파라미터를 조회 |
pageContext |
pageContext 경로 조회 |
EL 태그의 간단한 예
전달된 request 객체에 저장된 정보 출력 예
name : ${ requestScope.name }
age : ${ requestScope.age }
phone : ${requestScope.phone }
name : ${ name }
age : ${ age }
phone : ${ phone }
ArrayList items = (ArrayList) request.getAttribute("items");
ArrayList와 같이 전달된 값을 출력하는 예
0 : ${ requestScope.items[0] }
1 : ${ requestScope.items[1] }
2 : ${ requestScope.items[2] }
0 : ${ items[0] }
1 : ${ items[1] }
2 : ${ items[2] }
전달된 객체의 필드 값들 출력 예, member라는 객체를 request 형식으로 받음
이름 : ${ member.name }
나이 : ${ member.age }
전화번호 : ${ member.phone }
이메일 : ${ member.email }
Parameter로 넘어온 값 출력
<%
String pName = request.getParameter("name");
int price = Integer.parseInt(request.getParameter("price"));
String[] pNo = request.getParameterValues("no");
String option = request.getParameter("option");
%>
이와 같이 받던 데이터를 아래와 같이 간단하게
상품명 : ${ param.name }
가격 : ${ param.price }
제품번호 : ${ paramValues.no[0] }와 ${ paramValues.no["1"] }
옵션 : ${ (empty param.option)?"옵션없음":param.option }
스코프를 이용하여 구분지어 출력
Request
이름 : ${ requestScope.member.name }
나이 : ${ requestScope.member.age }
전화번호 : ${ requestScope.member.phone }
이메일 : ${ requestScope.member.email }
Session
이름 : ${ sessionScope.member.name }
나이 : ${ sessionScope.member.age }
전화번호 : ${ sessionScope.member.phone }
이메일 : ${ sessionScope.member.email }
동일한 이름의 네이밍이 있다면 request가 우선되어 출력됨
이름 : ${ member.name }
나이 : ${ member.age }
전화번호 : ${ member.phone }
이메일 : ${ member.email }
간단한 예 이외에 내장 객체들은 다음 게시글에서 쭉 사용한다.
'Spring Framework, MyBatis > 02. 사용법' 카테고리의 다른 글
[MyBatis]02-06. JSP Exception 오류 처리 (0) | 2019.01.20 |
---|---|
[MyBatis]02-05. MyBatis에서 바꿀 MVC 폴더 구조 (0) | 2019.01.20 |
[JSTL]02-04.JSTL Formatting Tags, Function Tags 예 (0) | 2019.01.20 |
[JSTL]02-03.JSTL 태그 종류 및 Core Tags 예 (0) | 2019.01.20 |
[Action Tag]02-01.Action태그 종류 및 예 (0) | 2019.01.20 |