更新時(shí)間:2016年09月29日16時(shí)59分 來(lái)源:傳智播客JAVA培訓(xùn)學(xué)院 瀏覽次數(shù):
public class MyTag implements SimpleTag{ private PageContext pageContext; private JspFragment body; @Override public void doTag() throws JspException, IOException { //向頁(yè)面中輸出內(nèi)容 pageContext.getOut().print("hello tag"); } @Override public JspTag getParent() { return null; } @Override public void setJspBody(JspFragment jspBody) { this.body=jspBody; } @Override public void setJspContext(JspContext pc) { this.pageContext=(PageContext) pc;//將參數(shù)pc賦值給成員變量pageContext } public void setParent(JspTag parent) {} } |
<?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>itcast</short-name> <uri>http://m.fskzgqt.cn/tags/it-1.0</uri> </taglib> |
<?xml version="1.0" encoding="UTF-8"?> <taglib xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd" version="2.1"> <description>JSTL 1.1 core library</description> <display-name>JSTL core</display-name> <tlib-version>1.1</tlib-version> <short-name>c</short-name> <uri>http://java.sun.com/jsp/jstl/core</uri> <tlib-version>1.0</tlib-version> <jsp-version>1.2</jsp-version> <short-name>itcast</short-name> <uri>http://m.fskzgqt.cn/tags/it-1.0</uri> </taglib> |
<?xml version="1.0" encoding="UTF-8"?> <taglib xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd" version="2.1"> <tlib-version>1.0</tlib-version> <short-name>itcast</short-name> <uri>http://m.fskzgqt.cn/tags/it-1.0</uri> </taglib> |
<?xml version="1.0" encoding="UTF-8"?> <taglib xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd" version="2.1"> <tlib-version>1.0</tlib-version> <short-name>itcast</short-name> <uri>http://m.fskzgqt.cn/tags/it-1.0</uri> <tag> <name>MyTag</name> <tag-class>cn.itcast.tag.MyTag</tag-class> <body-content>empty</body-content> </tag> </taglib> |
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib prefix="it" uri="/WEB-INF/tld/itcast-tag.tld" %> <!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=UTF-8"> <title>Insert title here</title> </head> <body> <it:MyTag/> </body> </html> |
public class MyTag1 extends SimpleTagSupport{ @Override public void doTag() throws JspException, IOException { this.getJspContext().getOut().print("繼承SimpleTagSupport類的標(biāo)簽"); } } |
此處省略例1-5中的代碼 <tag> <name>MyTag1</name> <tag-class>cn.itcast.tag.MyTag1</tag-class> <body-content>empty</body-content> </tag> |
此處省略例1-6中的代碼 <br> SimpleTagSupport:<it:MyTag1/> |
北京校區(qū)