본문 바로가기

Web/기타

[EL] EL(2)

EL 사용 예제 1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
    pageContext.setAttribute("p1""Page Scope Value");
    request.setAttribute("r1""Request Scope Value");
    session.setAttribute("s1""Session Scope Value");
    application.setAttribute("a1""Application Scope Value");
%>    

<html>
    <body>
        pageContext.getAttribute("p1") : ${pageScope.p1 }<br>
        request.getAttribute("r1") : ${requestScope.r1 }<br>
        session.getAttribute("s1") : ${sessionScope.s1 }<br>
        application.getAttribute("a1") : ${applicationScope.a1 }<br>
        <br><br>
        pageContext.getAttribute("p1") : ${p1 }<br>
        request.getAttribute("r1") : ${r1 }<br>
        session.getAttribute("s1") : ${s1 }<br>
        application.getAttribute("a1") : ${a1 }<br>
    </body>
</html>
cs


scope를 명시적으로 표시해주어도 되고 겹치는 변수명이 없는 경우 표시해주지 않아도 된다.

변수명이 겹치는 경우, 작은 scope부터 찾는다.

1
2
pageContext.getAttribute("p1") : ${pageScope.p1 }<br>
pageContext.getAttribute("p1") : ${p1 }<br>
cs


el을 사용하지 않으면 jsp의 표현식을 이용해서 다음과 같이 표현해야 한다.

1
pageContext.getAttribute("p1") : <%= pageContext.getAttribute("p1"%>
cs






EL 사용 예제 2

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
    request.setAttribute("k"10);
    request.setAttribute("m"true);
%>    
 
<html>
    <body>
        k : ${k } <br>
        k + 5 : ${ k + 5 } <br>
        k - 5 : ${ k - 5 } <br>
        k * 5 : ${ k * 5 } <br>
        k / 5 : ${ k div 5 } <br><br>
        
        k : ${k }<br>
        m : ${m }<br><br>
        
        k > 5 : ${ k > 5 } <br>
        k < 5 : ${ k < 5 } <br>
        k <10 : ${ k <10} <br>
        k >= 10 : ${ k >= 10 } <br>
        m : ${ m } <br>
        !m : ${ !m } <br>
    </body>
</html>
cs














참고자료

https://www.edwith.org

'Web > 기타' 카테고리의 다른 글

[JSTL] JSTL - set, remove  (0) 2018.12.27
[JSTL] JSTL - if, choose, forEach, import  (0) 2018.12.27
[JSTL] JSTL 개요  (0) 2018.12.27
[EL] EL(1)  (0) 2018.12.26
[WEB] HTML 기초(id, class, data 속성)  (0) 2018.11.17