표준 액션 태그 이외에 개발자의 커스텀 태그 만들기
1. XML 태그
1)표준 액션 태그 : 표준(jsp :)
<태그 속성=값> : 태그는 (태그라이브러리:태그이름) ex) jsp:forward
forward : RequestDispatcher.forward()와 동일
<jsp:forward page=“exam03.jsp”></jsp:forward>
=> 이 때 forwarding 하고자 하는 page를 동적으로 할당할 수 있다.(exam12.jsp)
include : RequestDispatcher.include() 와 동일
<jsp:include page=“”></jsp:include> (exam04.jsp)
=> 이 때 including 하고자 하는 page를 동적으로 할당할 수 있다.
========bean 처리 태그
useBean
getProperty
setProperty
=====================
2)커스텀 태그 : 개발자가 만들어 사용하는 태그
-JSTL :
-개발자
-태그 핸들러 클래스 작성(.class)
-TLD 파일 작성(xml 파일)
2. 커스텀 태그 작성 방법
1)태그 핸들러 클래스 작성(.class)
2)TLD 파일 작성(xml 파일),Tag Library Descriptor jsp태그<==>class태그
(예)
-WEB-INF 밑에 tlds 폴더 생성, 그 안에 myTag.tld파일을 만들어 보자
-xml 파일 생성 => 파일명 : myTag.tld
-create XML file from a DTD file
-select XML catalog entry : Sun, Inc // DTD Jsp Tag library 1.2 // EN
3)web.xml에 TLD 파일 등록 tld파일 <==>taglib-uri
<!-- tld 파일 등록 -->
<jsp-config>
<taglib>
<taglib-uri>http://myCustomTag.com</taglib-uri> <!-- 사용자 지정 -->
<taglib-location>/WEB-INF/tlds/myTag.tld</taglib-location>
</taglib>
</jsp-config>
4)JSP 파일에서 사용 전 TLD 파일 선언<%@ taglib uri="http://myCustomTag.com" prefix="my" %>
[실습]
com.sk.customTag.MyCustomTag.java
WEB-INF/tlds/myTag.tld
web.xml
exam16.jsp
[실습]
//com.sk.customTag.MyCustomTag.java
package com.sk.customTag;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;
public class MyCustomTag extends TagSupport {
// 시작 태그 시 실행
@Override
public int doStartTag() throws JspException {
System.out.println("doStartTag() 실행됨");
return super.doStartTag();
}
// 끝 태그 시 실행
@Override
public int doEndTag() throws JspException {
System.out.println("doEndTag() 실행됨");
return super.doEndTag();
}
}