创建一个JSP标记文件。
/WEB-INF/tags/foo.tag
<%@ tag body-content="empty" %><%@ attribute name="countryRequired" required="false" type="java.lang.Boolean" %><%@ attribute name="showAddress" required="false" type="java.lang.Boolean" %><%@ taglib prefix="f" uri="http://java.sun.com/jsf/core" %><%@ taglib prefix="h" uri="http://java.sun.com/jsf/html" %><%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %><h:panelGrid columns="2"> <h:outputLabel for="country" value="Country" /> <h:inputText id="country" value="#{bean.country}" required="${countryRequired}" /> <c:if test="${showAddress}"> <h:outputLabel for="address" value="Address" /> <h:inputText id="address" value="#{bean.address}" /> </c:if></h:panelGrid>声明和使用它的方式如下(无需其他XML配置):
<%@ taglib prefix="my" tagdir="/WEB-INF/tags" %>...<my:foo showAddress="true" />
请注意,像Facelets中一样,JSTL在这里也是一个“视图生成时间”标记。还要注意,您不能使用
#{}引用JSP标记属性。


