基本标签必须要满足三个文件
1。java文件 extends 有关Tag类
2。tld文件 让JSP runtime 知道怎么用标签
3。web中部署标签
例子:
package book.simpletasks;
import java.io.IOException;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspTagException;
import javax.servlet.jsp.tagext.TagSupport;
public class HelloWorldTag
extends TagSupport {
public int doStartTag()
throws JspException
{
try {
pageContext.getOut().print("Hello JSP tag World"); d
} catch(IOException ioe) { e
throw new JspTagException("Error:
IOException while writing to the user");
}
return SKIP_BODY;
}
}
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE taglib
PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN"
"http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd">
<taglib>
<tlibversion>1.0</tlibversion>
<jspversion>1.1</jspversion>
<shortname>simp</shortname>
<uri> http://www.manning.com/jsptagsbook/simple-taglib </uri>--------------这里可以不要
<info>
A simple sample tag library
</info>
<tag>
<name>hello</name>
<tagclass>book.simpletasks.HelloWorldTag</tagclass>
<bodycontent>empty</bodycontent>
<info>
Say hello.
</info>
</tag>
</taglib>
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
"http://java.sun.com/j2ee/dtds/web-app_2.2.dtd">
<web-app>
<taglib>
<taglib-uri>
http://www.manning.com/jsptagsbook/simple-taglib
</taglib-uri>
<taglib-location>
/WEB-INF/simpletags.tld
</taglib-location>
</taglib>
</web-app>
使用时在jsp中加入
<%@ taglib
uri="http://www.manning.com/jsptagsbook/simple-taglib"
prefix="jspx" %>
注意红色的部分要一一对应
保证在jsp页面装载的时候找得到tld文件