MapleStory Finger Point

๐ŸŸค JAVA/๐ŸŸค JSP

[JSP] EL (Expression Language)

HYEJU01 2024. 6. 28. 00:05

 

 

[ 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 ์ˆœ์œผ๋กœ
//์ด๋ฆ„๊ฐ’์„ ์ฐพ๊ธฐ ๋•Œ๋ฌธ