JSP/Servlet – 애트리뷰트를 지원하는 태그 파일 만들기
2016/02/14 - [프로그래밍/JSP/Servlet] - JSP/Servlet – 태그 파일을 이용해서 커스텀 액션 만드는 방법
<util:newLine color="blue" size="20" />
위처럼 애트리뷰트를 가지는 커스텀액션을 만들기 위해서는 attribute 지시자를 사용해야 합니다.
<%@attribute name="애트리뷰트 이름" %>
태그파일로 전달된 애트리뷰트는 다음과 같이 사용합니다.
<%= 애트리뷰트 이름 %> or ${애트리뷰트 이름 }
type 애트리뷰트를 통해서 거기에 원하는 데이터 타입을 지정할 수 있습니다.
<%@attribute name="애트리뷰트 이름" type="java.lang.Integer" %>
WEB-INF폴더 아래에 tags라는 폴더를 만들고 태그파일을 생성합니다.
newLine.tag
<%@tag body-content="empty" %>
<%@attribute name="color" %>
<%@attribute name="size" type="java.lang.Integer" %>
<FONT color=${color }>
<%
for(int cnt = 0; cnt < size; cnt++)
out.print("-");
%>
</FONT><BR>
TagTest.jsp
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<%@taglib prefix="util" tagdir="/WEB-INF/tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Insert title here</title>
</head>
<body>
<util:newLine color="blue" size="20"/>
테스트<BR>
<util:newLine color="red" size="25"/>
</body>
</html>
실행 화면
다음과 같이 size와 color옵션을 적용한 대로 잘 나오네요.
'프로그래밍 > JSP Servlet' 카테고리의 다른 글
JSP/Servlet – SimpleTagSupport 클래스를 이용해서 태그 클래스 작성하기 (0) | 2016.02.22 |
---|---|
JSP/Servlet – 커스텀 액션에 변수를 사용해보자 (0) | 2016.02.22 |
JSP/Servlet – 커스텀 액션에 body를 추가해보자 (0) | 2016.02.21 |
JSP/Servlet – 동적 애트리뷰트를 지원하는 태그 파일 만들기 (0) | 2016.02.18 |
JSP/Servlet – 태그 파일을 이용해서 커스텀 액션 만드는 방법 (0) | 2016.02.14 |
JSP/Servlet – JSTL <fmt:requestEncoding> 커스텀 액션 사용하기 (0) | 2016.02.10 |
JSP/Servlet – JSTL 프로퍼티 파일에 변수 포함하기 (0) | 2016.02.10 |
JSP/Servlet – JSTL <fmt:setBundle>과 <fmt:bundle> <fmt:message> 커스텀 액션 사용하기 (0) | 2016.02.03 |