Expression Language

EL์ด๋ž€?

ํ‘œํ˜„์‹<%= %> ๋˜๋Š” ์•ก์…˜ ํƒœ๊ทธ<jsp:></jsp:>๋ฅผ ๋Œ€์‹ ํ•ด์„œ ๊ฐ’์„ ํ‘œํ˜„ํ•˜๋Š” ์–ธ์–ด์ด๋‹ค.

EL์€ ${value} ๋กœ ํ‘œํ˜„๋œ๋‹ค.

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
    ${ 10 }<br/>
    ${ 99.99 }<br/>
    ${ "ABC" }<br/>
    ${ true }<br/>
</body>
</html>

EL ์—ฐ์‚ฐ์ž

์—ฐ์‚ฐ์ž

์ข…๋ฅ˜

์‚ฐ์ˆ 

+, - , *, /, %

๊ด€๊ณ„ํ˜•

==, !=, <, > , <=, >=

์กฐ๊ฑด

a?b:c

๋…ผ๋ฆฌ

&&, ||

${ 1+2 }
${ 1-2 }
${ 1*2 }
${ (1>2)?1:2 }

์•ก์…˜ํƒœ๊ทธ๋กœ ์‚ฌ์šฉ๋˜๋Š” EL

<jsp:getProperty name=*"member" property="name"/>* ๋ฅผ ${ member.name } ๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

package com.javalec.ex;

public class MemberInfo {

        private String name;
        private String id;
        private String pw;

        public String getName() {
            return name;
        }
        public void setName(String name) {
            this.name = name;
        }
        public String getId() {
            return id;
        }
        public void setId(String id) {
            this.id = id;
        }
        public String getPw() {
            return pw;
        }
        public void setPw(String pw) {
            this.pw = pw;
        }
}
<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<jsp:useBean id="member" class="com.javalec.ex.MemberInfo" scope="page" />
<jsp:setProperty name="member" property="name" value="์ด๋ฆ„"/>
<jsp:setProperty name="member" property="id" value="abc"/>
<jsp:setProperty name="member" property="pw" value="123"/>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Insert title here</title>
</head>
<body>
    ์ด๋ฆ„ : <jsp:getProperty name="member" property="name"/><br />
    ์•„์ด๋”” : <jsp:getProperty name="member" property="id"/><br />
    ๋น„๋ฐ€๋ฒˆํ˜ธ : <jsp:getProperty name="member" property="pw"/><br />

    <hr />

    ์ด๋ฆ„ : ${ member.name }<br />
    ์•„์ด๋‹ค : ${ member.id }<br />
    ๋น„๋ฐ€๋ฒˆํ˜ธ : ${ member.pw }<br />

</body>
</html>

๋‚ด์žฅ ๊ฐ์ฒด

๋‚ด์žฅ ๊ฐ์ฒด

์„ค๋ช…

pageScope

page๊ฐ์ฒด๋ฅผ ์ฐธ์กฐํ•˜๋Š” ๊ฐ์ฒด

requestScope

request๊ฐ์ฒด๋ฅผ ์ฐธ์กฐํ•˜๋Š” ๊ฐ์ฒด

sessionScope

session๊ฐ์ฒด๋ฅผ ์ฐธ์กฐํ•˜๋Š” ๊ฐ์ฒด

applicationScope

application๊ฐ์ฒด๋ฅผ ์ฐธ์กฐํ•˜๋Š” ๊ฐ์ฒด

param

์š”์ฒญ ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ์ฐธ์กฐํ•˜๋Š” ๊ฐ์ œ

paramValues

์š”์ฒญ ํŒŒ๋ผ๋ฏธํ„ฐ(๋ฐฐ์—ด)๋ฅผ ์ฐธ์กฐํ•˜๋Š” ๊ฐ์ œ

initParam

์ดˆ๊ธฐํ™” ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ์ฐธ์กฐํ•˜๋Š” ๊ฐ์ฒด

cookie

cookie๊ฐ์ฒด๋ฅผ ์ฐธ์กฐํ•˜๋Š” ๊ฐ์ฒด

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>jsp_23_3_ex1_elex</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>

  <context-param>
      <param-name>con_name</param-name>
      <param-value>con_name์€ ํ™๊ธธ๋™ ์ž…๋‹ˆ๋‹ค.</param-value>
  </context-param>
  <context-param>
      <param-name>con_id</param-name>
      <param-value>con_id๋Š” abcde ์ž…๋‹ˆ๋‹ค.</param-value>
  </context-param>
  <context-param>
      <param-name>con_pw</param-name>
      <param-value>con_pw๋Š” 12345 ์ž…๋‹ˆ๋‹ค.</param-value>
  </context-param>

</web-app>

์—ฌ๋Ÿฌ servlet์—์„œ ํŠน์ • ๋ฐ์ดํ„ฐ๋ฅผ ๊ณต์œ ํ•ด์•ผํ•˜๋Š” ๊ฒฝ์šฐ context parameter๋ฅผ ์ด์šฉํ•ด์„œ ๊ณต์œ ํ•˜๋ฉด์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

obj.jsp

<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Insert title here</title>
</head>
<body>

    <form action="objelOk.jsp" method="get">
        ์•„์ด๋”” : <input type="text" name="id"><br />
        ๋น„๋ฐ€๋ฒˆํ˜ธ : <input type="password" name="pw">
        <input type="submit" value="login">
    </form>

    <% 
        application.setAttribute("application_name", "application_value");
        session.setAttribute("session_name", "session_value");
        pageContext.setAttribute("page_name", "page_value");
        request.setAttribute("request_name", "request_value");
    %>

</body>
</html>

objelOk.jsp

<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Insert title here</title>
</head>
<body>

    <%
        String id = request.getParameter("id");
        String pw = request.getParameter("pw");
    %>

    ์•„์ด๋”” : <%= id %> <br />
    ๋น„๋ฐ€๋ฒˆํ˜ธ : <%= pw %>

    <hr />

    ์•„์ด๋”” : ${ param.id } <br />
    ๋น„๋ฐ€๋ฒˆํ˜ธ : ${ param.pw } <br />
    ์•„์ด๋”” : ${ param["id"] } <br />
    ๋น„๋ฐ€๋ฒˆํ˜ธ : ${ param["pw"] }

    <hr />

    applicationScope : ${ applicationScope.application_name }<br />
    sessionScope : ${ sessionScope.session_name }<br />
    pageScope : ${ pageScope.page_name }<br />
    requestScope : ${ requestScope.request_name }

    <hr />
    <!-- context parameter๊ฐ’์„ ์ฐธ์กฐํ•ด์„œ ๊ฐ€์ ธ ์˜ฌ ์ˆ˜ ์žˆ๋‹ค.-->
    context ์ดˆ๊ธฐํ™” ํŒŒ๋ผ๋ฏธํ„ฐ<br />
    ${ initParam.con_name } <br />
    ${ initParam.con_id } <br />
    ${ initParam.con_pw } <br />
</body>
</html>

ELํ‘œ๊ธฐ๋ฒ•์„ ํ†ตํ•ด์„œ ์ฝ”๋“œ๊ฐ€ ๊ธด ๊ฒƒ(๊ฐ€๋…์„ฑ์ด ๋–จ์–ด์ง€๋Š”)์„ ๋” ๊ฐ„๋‹จํ•˜๊ฒŒ ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ๋‹ค.

Last updated