2.列表内容 在tld文件中注册
<?xml version="1.0" encoding="ISO-8859-1"?> <taglib xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd" verson="2.0"> <description>Simple tag examples</description> <tlib-version>1.0</tlib-version> <jspversion>2.3</jspversion> <short-name>My First Taglib Example</short-name> <tag> <name>dataFormatter</name> <tag-class>tag.Attribute</tag-class> <body-content>empty</body-content> <attribute> <name>header</name> <required>true</required> </attribute> <attribute> <name>items</name> <required>true</required> </attribute> </tag> </taglib>在添加在前面的例子用过的tld文件即可
3.测试 jsp文件:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@ taglib uri="/WEB-INF/mytags.tld" prefix="easy" %> <!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=ISO-8859-1"> <title>Test</title> </head> <body> <easy:dataFormatter header="Num" items="1,2,3"/> <easy:dataFormatter header="Alph"> <jsp:attribute name="items"> a,b,c </jsp:attribute> </easy:dataFormatter> </body> </html>这里使用了两种方法传递属性,一种是一个标签属性,另一种是attribute动作指令。
结果:
