본문 바로가기

Programming!

JSP 2.0 Dynamic Attributes

http://www.javabeat.net/tips/179-dynamic-attributes-in-tag-file-in-jsp-20.html

1) File Name : firstPage.jsp

<%@ page contentType="text/html" %> 
<%@ taglib prefix="my" tagdir="/WEB-INF/tags/mytags" %> 
<html> 
<head> 
<title>Headers</title> 
</head> 
<body bgcolor="white"> 
	<my:person Age="28" EmployeeId="74852" Name="Bruce Wayne"  />
</body> 
</html> 
2) File Name : person.tag
<%@ tag body-content="empty" dynamic-attributes="dynattrs" %> 
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 

<table border="1" width="30%" height="20%" style="background-color:#EFEFEF">  
	<c:forEach items="${dynattrs}" var="a"> 
	<tr> 
		<td>${a.key}</td> 
		<td>${a.value}</td> 
	</tr> 
	</c:forEach> 
</table> 
3) Output
EmployeeId 74852
Name Bruce Wayne
Age 28