Written by
최태열
on
on
JSP3
EL (Expression Language)
EL 이란?
브라우저 화면에 결과를 출력할 때, 간편하고 가독성있게 표현하는 방식
활용
경로 통일화
<button onclick="location.href='${pageContext.request.contextPath}/jsp01_scripting.jsp'">01 jsp로 이동</button>
url로 인해 발생되는 경로의 혼동을 방지할 수 있는 기술
${pageContext.request.contextPath} - context명까지의 경로를 통일화
객체 출력
ArrayList<DeptDTO> all = (ArrayList<DeptDTO>)(request.getSession().getAttribute("all"));
ArrayList<DeptDTO> all = ${sessionScope.all}
<%
// People( name, age )
ArrayList<People> all = new ArrayList<>();
all.add(new People("김철수",5));
all.add(new People("이훈이",5));
all.add(new People("한유리",5));
all.add(new People("맹구",5));
all.add(new People("흰둥이",1));
HashMap<String, ArrayList<People>> all2 = new HashMap<>();
all2.put("one", all);
session.setAttribute("sData2", all2);
%>
4. 세션에 저장된 sData2에 매핑된 데이터 중 이훈이 출력
: ${sessionScope.sData2.one[1].name}
복잡한 과정을 거치는 대신에 EL 태그를 활용해 손쉽게 객체를 가져올 수 있다.
request → requestScope session → sessionScope
request는 requestScope에서 저장한 name을 통해 불러 올 수 있으며
session은 sessionScope에서 불러올 수 있다.
Discussion and feedback