Java Reference
In-Depth Information
For your sample tag you will use your original hello tag and add the appropriate functionality
to handle a single name attribute. Listing 19.6 contains the source for your new tag.
package com.djs;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspTagException;
import javax.servlet.jsp.tagext.TagSupport;
public class HelloAttributeTag extends TagSupport {
private String name = new String();
public HelloAttributeTag() {
// Accessor to set the name
public void setName(String name) { = name;
// Method called when the closing hello tag is encountered
public int doEndTag() throws JspException {
try {
// We use the pageContext to get a Writer
// We then print the text string Hello
pageContext.getOut().print(“Hello “ + name);
catch (Exception e) {
throw new JspTagException(e.getMessage());
// We want to return SKIP_BODY because this Tag does not support
// a Tag Body
return SKIP_BODY;
public void release() {
// Call the parent's release to release any resources
Search WWH ::

Custom Search