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 ์ฐ์ฐ์
${ 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>
๋ด์ฅ ๊ฐ์ฒด
page๊ฐ์ฒด๋ฅผ ์ฐธ์กฐํ๋ ๊ฐ์ฒด
request๊ฐ์ฒด๋ฅผ ์ฐธ์กฐํ๋ ๊ฐ์ฒด
session๊ฐ์ฒด๋ฅผ ์ฐธ์กฐํ๋ ๊ฐ์ฒด
application๊ฐ์ฒด๋ฅผ ์ฐธ์กฐํ๋ ๊ฐ์ฒด
์์ฒญ ํ๋ผ๋ฏธํฐ๋ฅผ ์ฐธ์กฐํ๋ ๊ฐ์
์์ฒญ ํ๋ผ๋ฏธํฐ(๋ฐฐ์ด)๋ฅผ ์ฐธ์กฐํ๋ ๊ฐ์
์ด๊ธฐํ ํ๋ผ๋ฏธํฐ๋ฅผ ์ฐธ์กฐํ๋ ๊ฐ์ฒด
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ํ๊ธฐ๋ฒ์ ํตํด์ ์ฝ๋๊ฐ ๊ธด ๊ฒ(๊ฐ๋
์ฑ์ด ๋จ์ด์ง๋)์ ๋ ๊ฐ๋จํ๊ฒ ๊ตฌํํ ์ ์๋ค.