[JSP] EL(Expression Language)

mandarinduk·2021년 3월 17일
0

EL

표현식 또는 액션태그를 대신해서 값을 표현하는 언어

<%= value %> → (EL) ${ value }

EL 연산자

  • 산술: +, -, *, /, %
  • 관계형: ==, !=, <, >, <=, >=
  • 조건: a(조건식)? b : c
  • 논리: &&, ||

액션 태그로 사용되는 형식

  • 액션태그: <jsp: getProperty name="person" property="name" />

  • EL 방식: ${person.name}

<jsp:useBean id="person" class="jsp_study.Person" scope="page" />
<jsp:setProperty name="person" property="name" value="홍길동" />
<jsp:setProperty name="person" property="id" value="test" />
<jsp:setProperty name="person" property="pw" value="1234" />

// 액션태그
이름: <jsp:getProperty name="person" property="name" /> // 이름: 홍길동
ID: <jsp:getProperty name="person" property="id" /> // ID: test
PW: <jsp:getProperty name="person" property="pw" /> // PW: 1234

// EL
이름: ${person.name} // 이름: 홍길동
ID: ${person.id} // ID: test
PW: ${person.pw} // PW: 1234

EL 내장 객체

  • pageScope: page 객체를 참조하는 객체
  • requestScope: request 객체를 참조하는 객체
  • sessionScope: session 객체를 참조하는 객체
  • applicationScope: application 객체를 참조하는 객체
  • param: 요청 파라미터를 참조하는 객체
  • paramValues: 요청 파라미터(배열)를 참조하는 객체
  • initParam: 초기화 파라미터를 참조하는 객체
  • cookie: cookie 객체를 참조하는 객체
elObj.jsp

<body>
	<form action="post_elObj.jsp" method="get">
		ID: <input type="text" name="id" /><br/>
		PW: <input type="password" name="pw" /><br/>
		<input type="submit" value="로그인" />
	</form>
	
	<%
		application.setAttribute("appName", "appValue");
		session.setAttribute("sessionName", "sessionValue");
		pageContext.setAttribute("pageName", "pageValue");
		request.setAttribute("reqName", "reqValue");
	%>
</body>
  <context-param>
  	<param-name>cont_1</param-name>
    <param-value>강호동</param-value>
  </context-param>
  <context-param>
  	<param-name>cont_2</param-name>
    <param-value>이경규</param-value>
  </context-param>
  <context-param>
  	<param-name>cont_3</param-name>
    <param-value>유재석</param-value>
  </context-param>
post_elObj.jsp

<body>

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

ID: <%= id1 %> <br/>
PW: <%= pw %> <br/>

<hr/>

ID: ${param.id} <br/>
PW: ${param.pw} <br/>
ID: ${param["id"]} <br/>
PW: ${param["pw"]} <br/>

<hr/>

applicationScope: ${applicationScope.appName} <br/> // appValue
sessionScope: ${sessionScope.sessionName} <br/> // sessionValue
pageScope: ${pageScope.pageName} <br/> // 페이지를 벗어낫기 때문에 출력 X
requestScope: ${requestScope.reqName} <br/> // 페이지를 벗어낫기 때문에 출력 X

<hr/>
- context 초기화 파라미터 <br/>
${initParam.cont_1} <br/> // 강호동
${initParam.cont_2} <br/> // 이경규
${initParam.cont_3} <br/> // 유재석

</body>
profile
front-end 신입 개발자

0개의 댓글