⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tag-attribute.xtp

📁 解压在c盘
💻 XTP
字号:
<s1 title="Tag Attributes"><p>Tags become more useful once you add attributes.  This example createsa <var/ct:href/> tag.</p><p>With session rewriting, even browsers withoutcookies can support sessions.  However, every <var/&lt;a href>/> needs acall to <var/response.encodeURL()/>, which is annoying.  With the<var/ct:href/> tag, you get that for free.</p><s2 title="Using an attribute taglib"><example title="href.jsp">&lt;%@ taglib prefix="ct" uri="WEB-INF/tags.tld" %>Message: &lt;ct:href href="test.jsp">test link&lt;/ct:href></example><results>Message: &lt;a href="test.jsp;jsessionid=1234">test link&lt;/a></results></s2><s2 title="Defining the tag"><p>The href tag has a single attribute <var/href/>.  Corresponding to theattribute <var/href/>, the HrefTag classimplements <var/getHref()/> and <var/setHref()/> methods.</p><example title="HrefTag.java">package test;import java.io.*;import javax.servlet.jsp.*;import javax.servlet.jsp.tagext.*;public class HrefTag extends TagSupport  {  private String href;  public String getHref()  {    return href;  }  public void setHref(String href)  {    this.href = href;  }  public int doStartTag() throws JspException  {    try {      JspWriter out = pageContext.getOut();      HttpServletResponse response;      response = (HttpServletResponse) pageContext.getResponse();      out.print("&lt;a href=\"");      out.print(response.encodeURL(href));      out.print("\">");    } catch (IOException e) {    }        return EVAL_BODY;  }  public int doEndTag() throws JspException  {    try {      pageContext.getOut().print("&lt;/a>");    } catch (IOException e) {    }        return EVAL_PAGE;  }}</example></s2><s2 title="Attribute Configuration"><p>Each expected attribute needs an entry in the .tld.  In this case,<var/href/> is a required attribute, so the configuration needs toset <var/required/>.  By setting <var/required/>, the JSP parser candetect errors at parse-time, making it easier to develop JSP pages withthe tag library.</p><example title="WEB-INF/tag.tld">&lt;taglib>  &lt;tag>    &lt;name>href&lt;/name>    &lt;tagclass>test.HrefTag&lt;/tagclass>    &lt;attribute>      &lt;name>href&lt;/name>      &lt;required>true&lt;/required>    &lt;/attribute>  &lt;/tag>&lt;/taglib></example></s2></s1>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -