Java JSP With A Custom Tag


To download source right-click here and "Save As...".

package tags;  //note: must be in a package

import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;

public class HelloTag extends TagSupport {
    public int doStartTag() {
        try {
            //use JspWriter to get output to your JSP
            JspWriter jspWriterOutput = pageContext.getOut();
            jspWriterOutput.print("Hello Tag!");
        } catch (IOException ioEx) {
            System.out.println("IOException in HelloTag " + ioEx);
        return (SKIP_BODY);
To download source right-click here and "Save As...".



The helloTag I show was generated by NetBeans, and then I modified it just a little. I generally like to code my own XML files, but even the Sun tutorial on custom tags suggests letting your ide do it.

The tld files can be put directly into WEB-INF. I accidentally put mine in the directory with the tag class file, and I now prefer it that way.


The Java 2 Platform Specification
Core JSP by Damon Hougland and Aaron Tavistock
Core Servlets and JavaServer Pages by Marty Hall
Sign in to be the first to comment on Java JSP With A Custom Tag.