1.编写自定义标签类
package com.crm.utils;
import java.io.IOException;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;
public class Mytag extends TagSupport {
@Override
public int doStartTag() throws JspException {
JspWriter out = super.pageContext.getOut();
try {
out.print("<span>这个是自定义标签输出的内容!</span>");
} catch (IOException e) {
e.printStackTrace();
}
return super.doStartTag();
}
}
2.编写tld描述文件
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE taglib
PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"
"http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd">
<taglib>
<tlib-version>2.0</tlib-version>
<jsp-version>1.2</jsp-version>
<short-name>myTag</short-name>
<uri>http://rzy/myTag/</uri>
<tag>
<name>page</name>
<tag-class>com.crm.utils.Mytag</tag-class>
<body-content>JSP</body-content>
</tag>
</taglib>
3.使用自定义标签,页面的引入
<%@ taglib prefix=“myTag” uri=“http://rzy/myTag/”%>
myTag:out</myTag:out>