日期:2014-05-16 浏览次数:20414 次
package com.fox.mytag;
import java.io.IOException;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;
public class HelloMyTag extends TagSupport {
	@Override
	public int doEndTag() throws JspException {
		JspWriter out = pageContext.getOut();
		try {
			out.print("do End Tag ");
		} catch (IOException e) {
			e.printStackTrace();
		}
		return super.doEndTag();
	}
	@Override
	public int doStartTag() throws JspException {
		JspWriter out = pageContext.getOut();
		try {
			out.print("<font color=\"red\">hello!</font>");
		} catch (IOException e) {
			e.printStackTrace();
		}
		return super.doStartTag();
	}
	
}<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 http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"
    version="2.0">
    <tlib-version>1.0</tlib-version>
    <short-name>myTagLib</short-name>
    <uri>/myTag</uri>
    <tag>
    	<name>helloTag</name>
    	<tag-class>com.fox.mytag.HelloMyTag</tag-class>
    	<body-content>empty</body-content>
    </tag>
    </taglib><jsp-config> <taglib> <taglib-uri>/myTag</taglib-uri> <taglib-location>/WEB-INF/tag/mytag.tld</taglib-location> </taglib> </jsp-config>