1.准备自定义JAVABEAN文件
import java.io.IOException;
import javax.servlet.jsp.JspTagException;
import javax.servlet.jsp.tagext.TagSupport;
public class CustomTag extends TagSupport {
public int doEndTag() throws JspTagException
{
try {
pageContext.getOut().write("Hello word!");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return EVAL_PAGE;
}
}
2.新增TAGSAMPLE.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>1.0</tlib-version>
<jsp-version>1.2</jsp-version>
<short-name>1.2</short-name>
<tag>
<name>hello</name>
<tag-class>zf.CustomTag</tag-class>
<body-content>empty</body-content>
</tag>
</taglib>
3.在WEB.xml新增节点
<jsp-config>
<taglib>
<taglib-uri>http://java.sun.com/jsp/jstl/core</taglib-uri>
<taglib-location>/WEB-INF/tag/TAGSAMPLE.TLD</taglib-location>
</taglib>
</jsp-config>
4.在引用 页面加入:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="ewf" %>
5.可以直接引用自定义的页面控件
<ewf:hello></ewf:hello>
6.注意事項 :
提示錯誤:Can not find the tag library descriptor for "http://java.sun.com/jsp/jstl/core"
解決方式:引用以下兩個jar包jstl.jar,standard.jar