📄 tag-hello.xtp
字号:
<s1 title="Empty Tag"><ul><li>Client JSP using the taglib<li>Tag class definition (HelloTag.java)<li>Tag configuration (hello.tld)</ul><s2 title="Using a taglib"><p>Using a taglib in a JSP file has two steps. First, the JSP needs todefine the <var/prefix/> and the <var/tld/> (tag library descriptor)for the tag.</p><p>Normally, JSP copies bytes from the .jsp to the browser withoutinterpreting it. The <var/taglib/> directive tells the JSP engine totreat elements starting with the prefix as JSP extension tags. </p><example title="hello.jsp"><%@ taglib prefix="ct" uri="WEB-INF/hello.tld" %>Message: <ct:hello/></example><results>Message: hello, world</results></s2><s2 title="Defining the tag"><p>Many simple tags can just extend <var/TagSupport/>. The hello tagimplements <var/doStartTag/>. When the hello tag starts, the JSP willexecute doStartTag. In this case, it'll print "hello, world".</p><p>Since the content of the hello tag doesn't matter, HelloTagreturns <var/SKIP_BODY/>. Empty tags will generallyreturn <var/SKIP_BODY/>.</p><example title="HelloTag.java">package test;import java.io.*;import javax.servlet.jsp.*;import javax.servlet.jsp.tagext.*;public class HelloTag extends TagSupport { public int doStartTag() throws JspException { try { pageContext.getOut().println("hello, world"); } catch (IOException e) { } return SKIP_BODY; }}</example></s2><s2 title="Configuring the tag"><p>Finally, you need to configure the tag in a .tld (tag librarydescriptor) file. The .tld matches the tag name <var/hello/> with the tagclass <var/test.HelloTag/>.</p><example title="WEB-INF/hello.tld"><taglib> <tag> <name>hello</name> <tagclass>test.HelloTag</tagclass> </tag></taglib></example></s2></s1>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -