• hessian
  • quercus/php
  • resin 3.0
  • resin 3.1
  • resin 4.0

  • changes
  • configuration
  • examples
  • installing
  • overview
  • starting

  • guide: admin
  • admin
  • amber
  • bam
  • caching
  • clustering
  • comet
  • database
  • deployment
  • ejb 3.0
  • embedding
  • filters
  • ioc
  • jsf
  • jsp
  • logging
  • messaging
  • quercus
  • remoting
  • security
  • resources
  • servlets
  • third-party
  • troubleshooting
  • virtual host
  • watchdog
  • webapp
  • HOME
  • ABOUT
  • ARTICLES
  • WORKSPACE
  • NEWS
  • PROJECTS
  • PRODUCTS
  • STORE
resin $resin/java_tut/tag-attribute.xtp

Tags become more useful once you add attributes. This example creates a ct:href tag.

With session rewriting, even browsers without cookies can support sessions. However, every <a href> needs a call to response.encodeURL(), which is annoying. With the ct:href tag, you get that for free.

  • hessian
  • quercus/php
  • resin 3.0
  • resin 3.1
  • resin 4.0

  • changes
  • configuration
  • examples
  • installing
  • overview
  • starting

  • guide: admin
  • admin
  • amber
  • bam
  • caching
  • clustering
  • comet
  • database
  • deployment
  • ejb 3.0
  • embedding
  • filters
  • ioc
  • jsf
  • jsp
  • logging
  • messaging
  • quercus
  • remoting
  • security
  • resources
  • servlets
  • third-party
  • troubleshooting
  • virtual host
  • watchdog
  • webapp
  • HOME
  • ABOUT
  • ARTICLES
  • WORKSPACE
  • NEWS
  • PROJECTS
  • PRODUCTS
  • STORE
<%@ taglib prefix="ct" uri="WEB-INF/tags.tld" %> Message: <ct:href href="test.jsp">test link</ct:href> Message: <a href="test.jsp;jsessionid=1234">test link</a>

The href tag has a single attribute href. Corresponding to the attribute href, the HrefTag class implements getHref() and setHref() methods.

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("<a href=\""); out.print(response.encodeURL(href)); out.print("\">"); } catch (IOException e) { } return EVAL_BODY; } public int doEndTag() throws JspException { try { pageContext.getOut().print("</a>"); } catch (IOException e) { } return EVAL_PAGE; } }

Each expected attribute needs an entry in the .tld. In this case, href is a required attribute, so the configuration needs to set required. By setting required, the JSP parser can detect errors at parse-time, making it easier to develop JSP pages with the tag library.

<taglib> <tag> <name>href</name> <tagclass>test.HrefTag</tagclass> <attribute> <name>href</name> <required>true</required> </attribute> </tag> </taglib>
  • HOME |
  • CONTACT US |
  • DOCUMENTATION |
  • SALES |
  • WIKI
Copyright (c) 1998-2009 Caucho Technology, Inc. All rights reserved.
caucho® , resin® and quercus® are registered trademarks of Caucho Technology, Inc.
  • HOME |
  • CONTACT US |
  • DOCUMENTATION |
  • SALES |
  • WIKI
Copyright (c) 1998-2009 Caucho Technology, Inc. All rights reserved.
caucho® , resin® and quercus® are registered trademarks of Caucho Technology, Inc.