개발/JSP&Servlet
jsp 태그 설정
by 카리3
2020. 8. 12.
1. TAG 설정
1-1) tospan.tag
<%@ tag language="java" body-content="tagdependent" pageEncoding="UTF-8"%>
<%@ attribute name="color" required="true" %>
<%@ attribute name="iterNum" required="true" type="java.lang.Integer" %>
<%
for(int i=0; i < iterNum; i++){
%>
<span style="background-color: ${color}">
♥<jsp:doBody/>♥
</span>
<%
}
%>
1-2) dynamicSelect.tag
<%@tag import="java.util.Iterator"%>
<%@tag import="java.util.Set"%>
<%@tag import="java.util.Map"%>
<%@ tag dynamic-attributes="optionMap" body-content="empty" pageEncoding="UTF-8"%>
<%
Map optionMap = (Map)jspContext.getAttribute("optionMap");
Set keySet = optionMap.keySet();
Iterator<String> keys = keySet.iterator();
%>
<select>
<%
while (keys.hasNext()) {
String key = keys.next();
%>
<option value="<%= key %>"><%= optionMap.get(key) %></option>
<%
}
%>
</select>
2. JSP 설정
<%@ taglib prefix="kangong" tagdir="/WEB-INF/tags" %>
<kangong:tospan color="blueviolet" iterNum="5">
hello
</kangong:tospan>
<kangong:dynamicSelect banana="바나나" apple="사과" grape="포도" />