Presentation is loading. Please wait.

Presentation is loading. Please wait.

제 14 장 커스텀 태그 2008 2학기 인터넷비즈니스과 강 환수 교수.

Similar presentations


Presentation on theme: "제 14 장 커스텀 태그 2008 2학기 인터넷비즈니스과 강 환수 교수."— Presentation transcript:

1 제 14 장 커스텀 태그 2008 2학기 인터넷비즈니스과 강 환수 교수

2 커스텀 태그 정의 반복적으로 사용되는 조건, 반복 등의 제어흐름과
다양한 태그의 표현 부분을 하나의 새로운 태그로 정의하여 사용할 수 있는 XML 유형의 사용자 정의 태그

3 커스텀 태그 생성 커스텀 태그 만드는 방법 버전 이름 특징 이름 구현 인터페이스 또는 상속 클래스 구현 파일 구현 방법
JSP 1.2 태그 처리기 자바 프로그래머에게 적합하고, 상대적으로 다소 복잡하며, JSP 2.0을 사용할 수 없는 경우 사용 JSP 2.0 자바 프로그래머에게 적합하며, JSP 1.2 태그 처리기에 비해 한결 간편해짐 태그 파일 JSP 프로그램과 유사하며 표현언어와 JSTL에 익숙한 프로그래머에게 적합 이름 구현 인터페이스 또는 상속 클래스 구현 파일 구현 방법 JSP 1.2 태그 처리기 javax.servlet.jsp.tagext.Tag javax.servlet.jsp.tagext.TagSupport 자바 파일 Tag 또는 TagSupport를 상속받은 자바 클래스 구현 JSP 2.0 javax.servlet.jsp.tagext.SimpleTag javax.servlet.jsp.tagext.SimpleTagSupport SimpleTag 또는 SimpleTagSupport를 상속받은 자바 클래스 구현 태그 파일 확장자가 tag인 태그 파일 JSP 프로그램과 같은 태그 파일 구현

4 JSP 2.0 커스텀 태그 개요 커스텀 태그 작성 절차 클래스 SimpleTagSupport 순서 이름 장소 파일 확장자 내용
1 태그 처리기(Tag Handler) [Resource: src] *.java 태그를 처리하는 자바 파일로 클래스 SimpleTagSupport를 상속(확장)하여 작성 2 태그 라이브러리 기술자(TLD) [WEB-INF/tld] *.tld 1에서 만든 태그를 JSP 페이지에서 사용할 수 있도록 태그 이름을 등록하는 절차 3 태그 활용 JSP 프로그램 [WebContent] *.jsp 2에서 등록한 태그이름을 taglib 지시자를 사용하여 이용 반환 유형 메소드 설명 void doTag() 태그가 수행해야 할 일을 처리하는 메소드로, 태그 처리 클래스에서 오버라이딩(overriding)해서 구현 JspFragment getJspBody() 태그의 몸체 부분을 반환 JspContext getJspContext() 페이지 context를 반환하며, 주로 getJspContext.getOut()을 통해 출력에 사용할 JspWriter 객체를 얻음

5 <myfirsttag:hello />
문자열 출력 커스텀 태그 작성 절차 <myfirsttag:hello /> 태그 hello는 몸체는 없으며 문자열 “Hello Custom Tag!!!”를 출력 필요 파일 순서 이름 장소 파일 이름 1 태그 클래스 작성 [Java Resources: src] HelloCustomTag.java 2 TLD 작성 [WEB-INF/tld] HelloCustomTag.tld 3 태그 활용 JSP 작성 [WebContent] HelloCustomTag.jsp

6 커스텀 태그를 위한 자바 파일 작성 HelloCustomTag.java

7 TLD 파일과 JSP 파일 작성 TLD 파일 JSP 파일
page language="java" contentType="text/html; charset=EUC-KR" pageEncoding="EUC-KR"%> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=EUC-KR"> <title>커스텀 태그</title> </head> <body> taglib uri="/WEB-INF/tld/HelloCustomTag.tld" prefix="myfirsttag" %> <H2>첫 커스텀 태그 예제 </H2> <center><HR> <myfirsttag:hello /> </center> </body> </html>

8 속성이 있는 커스텀 태그 만들기 테이블 출력 커스텀 태그 작성 절차 순서 이름 장소 파일 이름 비고 1 태그 처리기
[Java Resources: src] SelectStudentTag.java 속성에 대한 setter getter 2 TLD [WEB-INF/tld] SelectStudentTag.tld 속성 처리 3 태그 활용 JSP 프로그램 [WebContent] SelectStudentTag.jsp

9 태그 파일 개요 태그 파일의 장점 태그 파일로 커스텀 태그 작성 절차
자바에 익숙하지 않은 비개발자도 재사용이 가능한 커스텀 태그를 작성 프로그래머도 더 쉽게 작업 HTML 코드와 같은 표현 부분이 많은 모듈을 태그로 만든다면 태그 처리기 방식보다 적합 태그 파일로 커스텀 태그 작성 절차 순서 이름 장소 파일 확장자 설명 1 태그 파일(Tag File) [WEB-INF/tags] *.tag 태그를 처리하는 태그 파일로 JSP 파일과 비슷해 작성이 쉽고, 간단함 2 태그 활용 JSP 프로그램 [WebContent] *.jsp 위에서 만든 태그 파일 이름을 태그로 사용하며, taglib 지시자를 사용하여 이용

10 <mytag:hello />
문자열 출력 커스텀 태그 작성 절차 <mytag:hello /> 태그 hello는 몸체는 없으며 문자열 “Hello Custom Tag using Tag File !!!”를 출력하는 태그 순서 이름 장소 파일 이름 1 태그 파일 [WEB-INF/tags] hello.tag 2 태그 활용 JSP 프로그램 [WebContent] HelloCustomTagFile.jsp

11 태그 파일로 만드는 구구단 커스텀 태그 구구단 커스텀 태그 작성 절차 순서 이름 장소 파일 이름 1 태그 파일
[WEB-INF/tags] multiplication.tag 2 태그 활용 JSP 프로그램 [WebContent] multiplicationtable.jsp

12 Multiplication.tag tag body-content="scriptless" pageEncoding="euc-kr" description="구구단(multiplication table) 출력태그"%> attribute name="begin" %> attribute name="end" %> attribute name="bgcolor" %> taglib prefix="c" uri=" %> <c:if test="${empty(begin)}" var="bool"> <c:set var="begin" value="2" /> </c:if> <c:if test="${empty(end)}" var="bool"> <c:set var="end" value="9" /> <c:set var="bgcolor" value="white" /> <center> <H2><jsp:doBody /></H2> <table width=100% border=1 cellpadding=1 bgcolor="${bgcolor}" > <c:forEach var="i" begin="${begin}" end="${end}" > <tr align="center" > <c:forEach var="j" begin="1" end="9" > <td>${i} * ${j} = ${i * j}</td> </c:forEach> </tr> </table> </center> <p><hr>

13 JSP 프로그램과 결과 page language="java" contentType="text/html; charset=EUC-KR" pageEncoding="EUC-KR"%> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=EUC-KR"> <title>커스텀 태그</title> </head> <body> <h2> 태그 파일을 이용한 커스텀 태그 : multiplication </h2> <hr> taglib tagdir="/WEB-INF/tags" prefix="mytag" %> <mytag:multiplication> 구구단(2단에서 9단까지) </mytag:multiplication> <mytag:multiplication end="5" bgcolor="linen"> 구구단(2단에서 5단까지) <mytag:multiplication begin="3" end="7" bgcolor="yellow"> 구구단(3단에서 7단까지) </body> </html>

14 Thank You !


Download ppt "제 14 장 커스텀 태그 2008 2학기 인터넷비즈니스과 강 환수 교수."

Similar presentations


Ads by Google