users logged on. 출력결과 There are currently 15 users logged on. Web Programming"> users logged on. 출력결과 There are currently 15 users logged on. Web Programming">

Presentation is loading. Please wait.

Presentation is loading. Please wait.

JSP Expression Language

Similar presentations


Presentation on theme: "JSP Expression Language"— Presentation transcript:

1 JSP Expression Language
Internet Computing KUT Youn-Hee Han

2 Why JSP EL? Goal of Java EL Let’s think of it!!!
EL은 서버측 상태 (Server-side States)를 프리젠테이션 출력에 통합하는 것을 쉽게 해준다. JSP 의 기본 문법을 보완하는 기능 Let’s think of it!!! request 객체에서 사용 통계(usage statistics)에 관한 정보를 가져와 출력하는 JSP 코딩하기 방법 1] Scriptlet를 이용해서 출력 생성하기 구식의 JSP 1.0 방식 가급적 이런 코딩은 피하는 것이 좋음 There are currently <% String ss = request.getParameter("stats"); out.print(ss); %> users logged on. 출력결과 There are currently 15 users logged on. Web Programming

3 Why JEXL? 방법 2] JSP expression으로 출력 생성하기 방법 3] 커스텀 태그를 이용해서 출력 생성하기
역시 구식 방법 그러나, 가장 흔하게 사용하는 방법이며 초보자를 고려하여 많은 사람들을 배려하는 차원에서 이렇게 코딩하는 것도 좋음 방법 3] 커스텀 태그를 이용해서 출력 생성하기 새로운 기술을 활용한 좋은 방법, 그러나… 이와 같이 간결한 프리젠테이션을 얻고자 한다면, 개발자는 자바 클래스와 XML 포맷으로 된 TLD 파일을 모두 작성해야만 한다. 방법 4] JSP EL 사용하여 출력 생성하기 There are currently <%= request.getParameter("stats") %> users logged on. There are currently <myTags:userCount/> users logged in. There are currently ${param.stats} users logged in. Web Programming

4 JSP EL 용법 JSP EL 용법 항상 ${과 }사이에 작성된다. 다음 두 장소에서만 쓰여진다. In static text
In any standard or custom tag attribute <ul> <c:forEach var="k" items="${colors}"> <li><font color="${k}">This line is ${k}</font>. </c:forEach> </ul> <font color=”${cr}”> Hi, ${user}. You are <user:age style=”${style}”/> years old. </font> <${tag} var="x"/>  잘못된 사용 예 Web Programming

5 JSP EL 용법 JSP EL 용법 ${ } 내부에 사용할 수 있는 객체 11개의 기본 객체 [교재 382 페이지 참조]
pageContext: The context for the JSP page. Provides access to various objects including: servletContext: The context for the JSP page's servlet session: The session object for the client. request: The request triggering the execution of the JSP page. response: The response returned by the JSP page. param, paramValues header, headerValues cookie initParam pageScope, requestScope, sessionScope, applicationScope Web Programming

6 예제 1 교재 382 확장 예제 /2006777888/useELObject.jsp
page contentType = "text/html; charset=euc-kr" %> <% request.setAttribute("name", "홍길동"); session.setAttribute("school", "KUT"); application.setAttribute("year", "sophomore"); application.setAttribute("name", "춘향"); Cookie cookie = new Cookie ("ID","yhhan"); response.addCookie(cookie); %> <html><body> 요청 URI: ${pageContext.request.requestURI} <br> test1: ${pageContext.request.queryString} <br> test2: ${pageContext.request.requestedSessionId} <br> test3: ${pageContext.request.session} <br> request의 name 속성: ${requestScope.name} <br> session의 school 속성: ${sessionScope.school} and ${school}<br> application의 year 속성: ${applicationScope.year} and ${year}<br> application의 name 속성: ${applicationScope.name} and ${name}<br> code 파라미터: ${param.code} <br> cookie: ${cookie.ID.value} </body> </html> Web Programming

7 EL Evaluating Example Web Programming

8 Javabeans & EL StudentInfo 자바빈  확인
/ /WEB-INF/src/kut/ime/StudentInfo.java package kut.ime; public class StudentInfo { private String id; private String name; private String address; private String ; public String getId() { return id; } public String getName() { return name; public String getAddress() { return address; public String get () { return ; public void setId(String val) { this.id = val; } public void setName(String val) { this.name = val; public void setAddress(String val) { this.address = val; public void set (String val) { this. = val; 컴파일: sjc.bat  확인 Web Programming

9 Javabeans & EL 자바빈 사용하기 /2006777888/useELObject2.jsp
page contentType = "text/html; charset=euc-kr" %> isELIgnored="false" %> <jsp:useBean id="john" scope="request" class="kut.ime.StudentInfo" /> <jsp:setProperty name="john" property="id" value="1111" /> <jsp:setProperty name="john" property="name" value="요한" /> <jsp:setProperty name="john" property="address" value="서울 중구" /> <jsp:setProperty name="john" property=" " /> <% kut.ime.StudentInfo tom = new kut.ime.StudentInfo(); tom.setId("1112"); tom.setName("탐"); tom.setAddress("대전 서구"); %> <html> <body> <%= john.getName() %> (<%= john.getId() %>) 회원님 안녕하세요. <BR> <%= tom.getName() %> (<%= tom.getId() %>) 회원님 안녕하세요. <BR> </body> </html> Web Programming

10 Javabeans & EL 자바빈과 EL /2006777888/useELObject2.jsp
page contentType = "text/html; charset=euc-kr" %> isELIgnored="false" %> <jsp:useBean id="john" scope="request" class="kut.ime.StudentInfo" /> <jsp:setProperty name="john" property="id" value="1111" /> <jsp:setProperty name="john" property="name" value="요한" /> <jsp:setProperty name="john" property="address" value="서울 중구" /> <jsp:setProperty name="john" property=" " /> <% kut.ime.StudentInfo tom = new kut.ime.StudentInfo(); tom.setId("1112"); tom.setName("탐"); tom.setAddress("대전 서구"); %> <html> <body> <%= john.getName() %> (<%= john.getId() %>) 회원님 안녕하세요. <BR> ${john.name} (${john.id}) 회원님 안녕하세요.<BR> <%= tom.getName() %> (<%= tom.getId() %>) 회원님 안녕하세요. <BR> ${tom.name} (${tom.id}) 회원님 안녕하세요. </body> </html> Web Programming


Download ppt "JSP Expression Language"

Similar presentations


Ads by Google