/ JAVA

EL(Expression Language)

Expression Language

  • 표현식 또는 액션 태그를 대신해서 값을 표현하는 언어
  • 코드의 간결화를 위해 사용

표현식
${1+2}<br/>
${1-2}<br/>
${(1>2) ? 1 : 2 }<br/>

<br/>
<%= 1+2 %><br/>
<%= 1-2 %><br/>
<%= (1>2) ? 1 : 2 %>
======================================================
태그
이름 :   <jsp:getProperty name="member" property="name" />
아이디 : <jsp:getProperty name="member" property="id" />
비번:   <jsp:getProperty name="member" property="pw" />

<br/>
이름 :   ${member.name }
아이디 : ${member.id }
비번:   ${member.pw }

내장객체

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

예제1

입력 폼

<form action="objelOk.jsp">
    아이디 : <input type="text" name ="id">
    비밀번호 : <input type="password" name ="pw">
    <input type="submit" value="login">
</form>

출력 폼

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

아이디 <%= id %><br/>
비번 <%= pw %>

<hr/>

<!-- 내장객체 param사용 -->
아이디 ${param.id }<br/> <!-- request.getParameter("id");과 동일 -->
비밀번호 ${param.pw }<br/>

아이디 ${param["id"]}<br/> <!-- request.getParameter("id");과 동일 -->
비밀번호 ${param["pw"]}<br/>

=======================
<!--내장 객체-->
applicationScope : ${applicationScope.application_name }<br/>
sessionScope : ${sessionScope.session_name }<br/>
pageScope : ${pageScope.page_name }<br/>
requestScope : ${requestScope.request_name }

예제2

<!-- web.xml파일에서 context-param에 등록된 데이터를 들고 올때-->
<!-- 8-2에서 배운 ServletContext -->
<%  String id = getServletContext().getInitParameter("con_name");
    String pw = getServletContext().getInitParameter("con_id");
    String path = getServletContext().getInitParameter("con_pw");
%>

<%= id %><br/>
<%= pw %><br/>
<%= path %><br/>
============================
<!-- EL을 사용해서 가지고올때 -->
${initParam.con_name }<br/>
${initParam.con_id }<br/>
${initParam.con_pw }<br/>

References.