Class 2 Intermediate Java 30-IT-397  

BeginTable.class

package table;

// import the necessary libraries.
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
import java.io.*;

/**
 * Simple custom JSP tag that prints a copyright where inserted.
 *
 * 12/18/2001 jonesbr@email.uc.edu
 **/

public class BeginTable extends TagSupport {

    int border = 0;

    // method acts when the first tag is reached.
    public int doStartTag() {

        try {
            // Get an output stream for our tag's output.
            JspWriter out = pageContext.getOut();

            // Write the begin table tags.
            // If a border length was set as an attribute, it will have been assigned
            // automatically via the setStrBorder method below.  If so, we use that value.
            // If not, use the default of 0.
            out.print("<table border = " + border + "><tr>");

            // In case we have an error...
        } catch (IOException e) {
            System.out.println("Error in BeginTable: " + e.getMessage());
        }

        // Tell it that we don't need to look at the contents between the tags.
        return(SKIP_BODY);

    // End the method.
    }

    public void setStrBorder(String strBorder) {
        border = Integer.parseInt(strBorder);
    }

// End the class.
}

 Back

Created by:  Brandan Jones December 17, 2001