Home | | Internet & World Wide Web HOW TO PROGRAM | | Internet Programming | | Web Programming | Custom Tag Libraries - JavaServer Pages (JSP)

Chapter: Internet & World Wide Web HOW TO PROGRAM - JavaServer Pages (JSP): Bonus for Java™ Developers

Study Material, Lecturing Notes, Assignment, Reference, Wiki description explanation, brief detail

Custom Tag Libraries - JavaServer Pages (JSP)

Throughout this chapter, you have seen how JavaServer Pages can simplify the delivery of dynamic Web content. Our discussion continues with JSP custom tag libraries, which pro-vide another mechanism for encapsulating complex functionality for use in JSPs.

Custom Tag Libraries

 

Throughout this chapter, you have seen how JavaServer Pages can simplify the delivery of dynamic Web content. Our discussion continues with JSP custom tag libraries, which pro-vide another mechanism for encapsulating complex functionality for use in JSPs. Custom tag libraries define one or more custom tags that JSP implementors can use to create dy-namic content. The functionality of these custom tags is defined in Java classes that imple-ment interface Tag (package javax.servlet.jsp.tagext), normally by extending class TagSupport or BodyTagSupport. This mechanism enables Java programmers to create complex functionality for Web page designers who have no Java programming knowledge.

 

Previously, we introduced action <jsp:useBean> and JavaBeans to incorporate complex, encapsulated functionality in a JSP. In many cases, action <jsp:useBean> and JavaBeans can perform the same tasks as custom tags can. However, action <jsp:useBean> and JavaBeans have disadvantages—JavaBeans cannot manipulate JSP content and Web page designers must have some Java knowledge to use JavaBeans in a page. With custom tags, it is possible for Web page designers to use complex function-ality without knowing any Java.

 

In this section, we present three examples of custom tags. Each tag is part of a single custom tag library that we refer to as advjhtp1. A JSP includes a custom tag library with the taglib directive. Figure 31.29 summarizes the taglib directive’s attributes.


Each of the examples in this section uses directive taglib. There are several types of custom tags that have different levels of complexity. We demonstrate simple tags, simple tags with attributes and tags that can process their body elements. For complete details on custom tag libraries, see the resources in Section 31.9.

 

1. Simple Custom Tag

 

Our first custom tag example implements a simple custom tag that inserts the string “Wel-come to JSP Tag Libraries in a JSP. When implementing custom tags, you must define a tag-handler class for each tag that implements the tag’s functionality, a tag library descriptor that provides information about the tag library and its custom tags to the JSP container and a JSP that uses the custom tag. Figure 31.30 (customTagWelcome.jsp) demonstrates our first custom tag. At the end of this section, we discuss how to configure this example for testing on Tomcat.



<?xml version = "1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<!-- Fig. 10.30: customTagWelcome.jsp -->
<!-- JSP that uses a custom tag to output content. -->
<%-- taglib directive --%>
<%@ taglib uri = "advjhtp1-taglib.tld" prefix = "advjhtp1" %>
<html xmlns = "http://www.w3.org/1999/xhtml">

<head>
<title>Simple Custom Tag Example</title>
</head>
<body>
<p>The following text demonstrates a custom tag:</p>
<h1>
<advjhtp1:welcome />
</h1>
</body>
</html>

Fig. 31.30  JSP customTagWelcome.jsp uses a simple custom tag

 

The taglib directive at line 9 enables the JSP to use the tags in our tag library. The directive specifies the uri of the tag library descriptor file (advjhtp1-taglib.tld; Fig. 31.32) that provides information about our tag library to the JSP container and the prefix for each tag (advjhtp1). JSP programmers use the tag library prefix when referring to tags in a specific tag library. Line 20 uses a custom tag called welcome to insert text in the JSP. Note that the prefix advjhtp1: precedes the tag name. This enables the JSP container to interpret the meaning of the tag and invoke the appropriate tag handler. Also note that line 20 can be written with start and end tags as follows:

<advjhtp1:welcome> </advjhtp1:welcome>

 

Figure 31.31 defines class WelcomeTagHandler—the tag handler that implements the functionality of our custom tag welcome. Every tag handler must implement interface Tag, which defines the methods a JSP container invokes to incorporate a tag’s function-ality in a JSP. Most tag handler classes implement interface Tag by extending either class

TagSupport or class BodyTagSupport.


// Fig. 10.31: WelcomeTagHandler.java
// Custom tag handler that handles a simple tag.
package com.deitel.advjhtp1.jsp.taglibrary;
// Java core packages
import java.io.*;
// Java extension packages
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
public class WelcomeTagHandler extends TagSupport {

// Method called to begin tag processing
public int doStartTag() throws JspException
{
// attempt tag processing
try {

// obtain JspWriter to output content
JspWriter out = pageContext.getOut();
// output content
out.print( "Welcome to JSP Tag Libraries!" );
}
// rethrow IOException to JSP container as JspException
catch( IOException ioException ) {
throw new JspException( ioException.getMessage() );
}
return SKIP_BODY;  // ignore the tag's body
}
}

 

Fig. 31.31  WelcomeTagHandler custom tag handler.

 

Class WelcomeTagHandler implements interface Tag by extending class Tag-Support (both from package java.servlet.jsp.tagext). The most important methods of interface Tag are doStartTag and doEndTag. The JSP container invokes these methods when it encounters the starting custom tag and the ending custom tag, respectively. These methods throw JspExceptions if problems are encountered during custom-tag processing.

In this example, class WelcomeTagHandler overrides method doStartTag to output text that becomes part of the JSP’s response. Line 20 uses the custom tag handler’s pageContext object (inherited from class TagSupport) to obtain the JSP’s Jsp-Writer object that method doStartTag uses to output text. Line 23 uses the Jsp-Writer to output a string. Line 31 returns the static integer constant SKIP_BODY (defined in interface Tag) to indicate that the JSP container should ignore any text or other elements that appear in the tag’s body. To include the body content as part of the response, specify static integer constant EVAL_BODY_INCLUDE as the return value. This example does not require any processing when the ending tag is encountered by the JSP container, so we did not override doEndTag.

 

Figure 31.32 defines the custom tag library descriptor file. This XML document spec-ifies information required by the JSP container such as the version number of the tag library (element tlibversion), the JSP version number (element jspversion), information about the library (element info) and information about the tags in the library (one tag element for each tag). In this tag library descriptor, the tag element at lines 18–30 describes our welcome tag. Line 19 specifies the tag’s name—used by JSP programmers to access the custom functionality in a JSP. Lines 21–23 specify the tagclass—the custom tag handler class. This element associates the tag name with a specific tag handler class. Element bodycontent (line 25) specifies that our custom tag has an empty body. This value can also be tagdependent or JSP. Lines 27–29 specify information about the tag with an info element. [Note: We introduce other elements of the tag library descriptor as necessary. For a complete description of the tag library descriptor, see the JavaServer Pages 1.1 specification, which can be downloaded from java.sun.com/ products/jsp/download.html.]

 

 

    <?xml version = "1.0" encoding = "ISO-8859-1" ?>

    <!DOCTYPE taglib PUBLIC

    "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN"

    "http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd">

 

    <!-- a tag library descriptor -->

 

 

    <taglib>

    <tlibversion>1.0</tlibversion>

      <jspversion>1.1</jspversion>

      <shortname>advjhtp1</shortname>

 

      <info>

      A simple tab library for the examples

      </info>

 

      <!-- A simple tag that outputs content -->

      <tag>

      <name>welcome</name>

 

              <tagclass>

      com.deitel.advjhtp1.jsp.taglibrary.WelcomeTagHandler

      </tagclass>

 

              <bodycontent>empty</bodycontent>

 

<info>

      Inserts content welcoming user to tag libraries

      </info>

      </tag>

</taglib>

 

Fig. 31.32     Custom tag library descriptor file (advjhtp1-taglib.tld)

 

To test customTagWelcome.jsp in Tomcat, copy customTagWelcome.jsp and advjhtp1-taglib.tld into the jsp directory created in Section 31.3. Copy

 

WelcomeTagHandler.class into the advjhtp1 Web application’s WEB-INF\classes directory in Tomcat. [Note: Class WelcomeTagHandler must appear in its proper package director structure in classes directory. WelcomeTagHandler is defined in package com.deitel.advjhtp1.jsp.taglibrary.] Open your Web browser and enter the following URL to test customTagWelcome.jsp:

 

http://localhost:8080/advjhtp1/jsp/customTagWelcome.jsp

 

2. Custom Tag with Attributes

 

Many XHTML and JSP elements use attributes to customize functionality. For example, an XHTML element can specify a style attribute that indicates how the element should be formatted in a client’s Web browser. Similarly, the JSP action elements have attributes that help customize their behavior in a JSP. Our next example demonstrates how to specify at-tributes for your custom tags.

Figure 31.33 (customTagAttribute.jsp) is similar to Fig. 31.30. This example uses a new tag called, welcome2, to insert text in the JSP that is customized based on the value of attribute firstName. The screen capture shows the results of the welcome2 tags on lines 20 and 30. The tag at line 20 specifies the value "Paul" for attribute first-Name. Lines 26–28 define a scriptlet that obtains the value of request parameter name and assign it to String reference name. Line 30 uses the name in a JSP expression as the value for the firstName attribute. In the sample screen capture, this JSP was invoked with the following URL:

 

http://localhost:8080/advjhtp1/jsp/

customTagAttribute.jsp?firstName=Sean

 

    <?xml version = "1.0"?>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

     <!-- Fig. 10.x: customTagAttribute.jsp -->

     <!-- JSP that uses a custom tag to output content. -->

        

     <%-- taglib directive --%>

     <%@ taglib uri = "advjhtp1-taglib.tld" prefix = "advjhtp1" %>

      <html xmlns = "http://www.w3.org/1999/xhtml">

 

      <head>

      <title>Specifying Custom Tag Attributes</title>

      </head>

 

      <body>

      <p>Demonstrating an attribute with a string value</p>

      <h1>

      <advjhtp1:welcome2 firstName = "Paul" />

      </h1>

 

      <p>Demonstrating an attribute with an expression value</p>

<h1>

 

     <%-- scriptlet   to obtain "name" request parameter --%>

     <% 

     String name  = request.getParameter( "name" );

     %> 

      <advjhtp1:welcome2 firstName = "<%= name %>" />

      </h1>

      </body>

          </html>

 


 

Fig. 31.33  Specifying attributes for a custom tag

 

When defining the custom tag handler for a tag with attributes, you must provide methods that enable the JSP container to set the attribute values in the tag handler. Methods that manipulate attributes follow the same set- and get-method naming conventions as do JavaBean properties. Thus, the custom tag’s firstName attribute is set with method setFirstName. Similarly, the method to obtain the firstName attribute’s value would be getFirstName (we did not define this method for this example). Class Welcome2TagHandler (Fig. 31.34) defines its firstName variable at line 13 and a corresponding set method setFirstName (lines 37–40). When the JSP container encounters a welcome2 tag in a JSP, it creates a new Welcome2TagHandler object to process the tag and sets the tag’s attributes. Next, the container invokes method doStartTag (lines 16–34) to perform the custom tag processing. Lines 24–25 use the firstName attribute value as part of the text output by the custom tag.


 

      // Fig. 10.34: Welcome2TagHandler.java

      // Custom tag handler that handles a simple tag.

      package com.deitel.advjhtp1.jsp.taglibrary;

      // Java core packages

      import java.io.*;

      // Java extension packages

      import javax.servlet.jsp.*;

        import javax.servlet.jsp.tagext.*;

 

        public class Welcome2TagHandler extends TagSupport {

        private String firstName = "";

       public int doStartTag() throws JspException

        {

        // attempt tag processing

try {

          // obtain      JspWriter to output content

          JspWriter   out = pageContext.getOut();

                  

          // output     content

          out.print( "Hello " + firstName +

          ", <br         />Welcome to JSP Tag Libraries!" );

          }

        // rethrow IOException to JSP container as JspException

        catch( IOException ioException ) {

        throw new JspException( ioException.getMessage() );

        }

        return SKIP_BODY;  // ignore the tag's body

        }

        // set firstName attribute to the users first name

        public void setFirstName( String username )

        {

        firstName = username;

        }

}

 

Fig. 31.34  Welcome2TagHandler custom tag handler for a tag with an attribute.

 

 Before the welcome2 tag can be used in a JSP, we must make the JSP container aware of the tag by adding it to a tag library. To do this, add the tag element of Fig. 31.35 as a child of element taglib in the tag library descriptor advjhtp1-taglib.tld. As in the previous example, element tag contains elements nametagclassbodycon-tent and info. Lines 16–20 introduce element attribute for specifying the charac-teristics of a tag’s attributes. Each attribute must have a separate attribute element that contains the namerequired and rtexprvalue elements. Element name (line 17) specifies the attribute’s name. Element required specifies whether the attribute is required (true) or optional (false). Element rtexprvalue specifies whether the value of the attribute can be the result of a JSP expression evaluated at runtime (true) or whether it must be a string literal (false).

 

To test customTagAttribute.jsp in Tomcat, copy customTagAt-tribute.jsp and the updated advjhtp1-taglib.tld into the jsp directory cre-ated in Section 31.3. Copy Welcome2TagHandler.class into the advjhtp1 Web application’s WEB-INF\classes directory in Tomcat. [Note: This example will work only if the proper package-directory structure for Welcome2TagHandler is defined in the classes directory.] Open your Web browser and enter the following URL to test customTagAttribute.jsp:

 

http://localhost:8080/advjhtp1/jsp/

customTagAttribute.jsp?firstName=Sean

 

The text ?firstName=Sean in the preceding URL specifies the value for request pa-rameter name that is used by the custom tag welcome2 at line 30 in Fig. 31.33.


 

    <!-- A tag with an attribute -->

    <tag>

    <name>welcome2</name>

    <tagclass>

    com.deitel.advjhtp1.jsp.taglibrary.Welcome2TagHandler

    </tagclass>

         <bodycontent>empty</bodycontent>

 

      <info>

      Inserts content welcoming user to tag libraries. Uses

      attribute "name" to insert the user's name.

      </info>

      <attribute>

      <name>firstName</name>

      <required>true</required>

      <rtexprvalue>true</rtexprvalue>

      </attribute>

      </tag>

Fig. 31.35  Element tag for the welcome2 custom tag.

 

 3. Evaluating the Body of a Custom Tag

 

Custom tags are particularly powerful for processing the element body. When a custom tag interacts with the element body, additional methods are required to perform those interac-tions. The methods are defined in class BodyTagSupport. In our next example, we re-implement guestBookView.jsp (Fig. 31.23) and replace the JavaBean processing performed in the JSP with a custom guestlist tag.

 

Figure 31.36 (customTagBody.jsp) uses the custom guestlist tag at lines 41–52. Note that the JSP expressions in the body of element guestlist use variable names that are not defined in the JSP. These variables are defined by the custom tag handler when the custom tag is encountered. The custom tag handler places the variables in the JSP’s PageContext, so the variables can be used throughout the page. Although no rep-etition is defined in the JSP, the custom tag handler is defined to iterate over all the guests in the guestbook database. This action results in the creation of a table row in the resulting Web page for each guest in the database.

 

 

    <?xml version = "1.0"?>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"

    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

 

    <!-- customTagBody.jsp -->

 

 

    <%-- taglib directive --%>

    <%@ taglib uri = "advjhtp1-taglib.tld" prefix = "advjhtp1" %>

 

      <html xmlns = "http://www.w3.org/1999/xhtml">

 

 

      <head>

      <title>Guest List</title>

          <style type = "text/css">

          body {

          font-family: tahoma, helvetica, arial, sans-serif

          }

         

          table, tr, td, th {

          text-align: center;

          font-size: .9em;

          border: 3px groove;

          padding: 5px;

          background-color: #dddddd

          }

          </style>

          </head>

 

          <body>

          <p style = "font-size: 2em">Guest List</p>

         

          <table>

          <thead>

<th style = "width: 100px">Last name</th>      

<th style = "width: 100px">First name</th>      

<th style = "width: 200px">Email</th>    

</thead>    

         

<%-- guestlist custom tag --%>        

<advjhtp1:guestlist>     

<tr>  

<td><%= lastName %></td> 

         

<td><%= firstName %></td>

         

<td>  

<a href = "mailto:<%= email %>"> 

<%= email %></a>       

</td> 

</tr> 

          </advjhtp1:guestlist>

          </table>

          </body>

 

          </html>


Fig. 31.36  Using a custom tag that interacts with its body

 

As in guestBookView.jsp, the custom tag handler GuestBookTag (Fig. 31.37) creates a GuestDataBean to access the guestbook database. Class GuestBookTag extends BodyTagSupport, which contains several new methods including doInit-Body and doAfterBody (from interface BodyTag). Method doInitBody is called once, after doStartTag and before doAfterBody. Method doAfterBody can be called many times to process the body of a custom tag.

 

 

      // Fig. 10.37: GuestBookTag.java

      // Custom tag handler that reads information from the guestbook

      // database and makes that data available in a JSP.

      package com.deitel.advjhtp1.jsp.taglibrary;

      // Java core packages

      import java.io.*;

      import java.util.*;

        // Java extension packages

        import javax.servlet.jsp.*;

        import javax.servlet.jsp.tagext.*;

 

        // Deitel packages

        import com.deitel.advjhtp1.jsp.beans.*;

 

        public class GuestBookTag extends BodyTagSupport {

        private String firstName;

        private String lastName;

        private String email;

        private GuestDataBean guestData;

        private GuestBean guest;

        private Iterator iterator;

 

        // Method called to begin tag processing

        public int doStartTag() throws JspException

        {

        // attempt tag processing

try {

guestData = new GuestDataBean();

                  

          List list = guestData.getGuestList();

          iterator = list.iterator();

                  

          if ( iterator.hasNext() ) {        

          processNextGuest();     

                  

          return EVAL_BODY_TAG;   // continue body processing

          }      

          else  

          return SKIP_BODY;     // terminate body processing

          }

        // if any exceptions occur, do not continue processing

        // tag's body

        catch( Exception exception ) {

                   exception.printStackTrace();

        return SKIP_BODY;   // ignore the tag's body

        }

}

      // process body and determine if body processing

      // should continue

      public int doAfterBody()

      {

      // attempt to output body data

      try {

      bodyContent.writeOut( getPreviousOut() );

      }

 

      // if exception occurs, terminate body processing

      catch ( IOException ioException ) {

                   ioException.printStackTrace();

      return SKIP_BODY;// terminate body processing

}

          bodyContent.clearBody();

         

          if ( iterator.hasNext() ) {

          processNextGuest();

      return EVAL_BODY_TAG;// continue body processing

      }

      else

      return SKIP_BODY;// terminate body processing

      }

      // obtains the next GuestBean and extracts its data

      private void processNextGuest()

      {

      // get next guest

guest = ( GuestBean ) iterator.next();

          pageContext.setAttribute(

          "firstName", guest.getFirstName() );

         

          pageContext.setAttribute(

          "lastName", guest.getLastName() );

         

          pageContext.setAttribute(

          "email", guest.getEmail() );

          }

          }

Fig. 31.37  GuestBookTag custom tag handler

 

 

The JSP container invokes method doStartTag (lines 27–51) when it encounters the custom guestlist tag in a JSP. Lines 31–34 create a new GuestDataBean, obtain a List of GuestBeans from the GuestDataBean and create an Iterator for manipu-lating the ArrayList contents. If there are no elements in the list (tested at line 36), line 42 returns SKIP_BODY to indicate that the container should perform no further processing of the guestlist tag’s body. Otherwise, line 37 invokes private method processNex-tGuest (lines 80–93) to extract the information for the first guest and create variables con-taining that information in the JSP’s PageContext (represented with variable pageContext that was inherited from BodyTagSupport). Method process-NextGuest uses PageContext method setAttribute to specify each variable’s name and value. The container is responsible for creating the actual variables used in the JSP. This is accomplished with the help of class GuestBookTagExtraInfo (Fig. 31.38).

 

Method doAfterBody (lines 55–77)performs the repetitive processing of the guestlist tag’s body. The JSP container determines whether method doAfterBody should be called again, based on the method’s return value. If doAfterBody returns

 

EVAL_BODY_TAG, the container calls method doAfterBody again. If doAfterBody returns SKIP_BODY, the container stops processing the body and invokes the custom tag handler’s doEndTag method to complete the custom processing. Line 59 invokes writeOut on variable bodyContent (inherited from BodyTagSupport) to process the first client’s data (stored when doStartTag was called). Variable bodyContent refers to an object of class BodyContent (package javax.servlet.jsp.tagext). The argument to method writeOut is the result of method getPreviousOut (inherited from class BodyTagSupport), which returns the JspWriter object for the JSP that invokes the custom tag. This enables the custom tag to continue building the response to the client using the same output stream as the JSP. Next, line 68 invokes bodyContent’s method clearBody to ensure that the body content that was just output does not get pro-cessed as part of the next call to doAfterBody. Lines 70–76 determine whether there are more guests to process. If so, doAfterBody invokes private method processNext-Guest to obtain the data for the next guest and returns EVAL_BODY_TAG to indicate that the container should call doAfterBody again. Otherwise, doAfterBody returns SKIP_BODY to terminate processing of the body.

The JSP container cannot create variables in the PageContext unless the container knows the names and types of those variables. This information is specified by a class with the same name as the custom tag handler and that ends with ExtraInfo (GuestBook-TagExtraInfo in Fig. 31.38). ExtraInfo classes extend class TagExtraInfo (package javax.servlet.jsp.tagext). The container uses the information speci-fied by a subclass of TagExtraInfo to determine what variables it should create (or use) in the PageContext. To specify variable information, override method getVari-ableInfo. This method returns an array of VariableInfo objects that the container uses either to create new variables in the PageContext or to enable a custom tag to use existing variables in the PageContext. The VariableInfo constructor receives four arguments—a String representing the name of the variable, a String representing the variable’s class name, a boolean indicating whether or not the variable should be created by the container (true if so) and a static integer constant representing the variable’s scope in the JSP. The constants in class VariableInfo are NESTED, AT_BEGIN and AT_END. NESTED indicates that the variable can be used only in the custom tag’s body. AT_BEGIN indicates that the variable can be used anywhere in the JSP after the starting tag of the custom tag is encountered. AT_END indicates that the variable can be used any-where in the JSP after the ending tag of the custom tag.

 

Before using the guestlist tag in a JSP, we must make the JSP container aware of the tag by adding it to a tag library. Add the tag element of Fig. 31.39 as a child of element taglib in the tag library descriptor advjhtp1-taglib.tld. As in the previous example, element tag contains elements name, tagclass, bodycontent and info. Lines 10–12 introduce element teiclass to specify the custom tag’s ExtraInfo class.

 

 

    // Fig. 10.38: GuestBookTagExtraInfo.java

    // Class that defines the variable names and types created by

    // custom tag handler GuestBookTag.

    package com.deitel.advjhtp1.jsp.taglibrary;

    // Java core packages

    import javax.servlet.jsp.tagext.*;

 

    public class GuestBookTagExtraInfo extends TagExtraInfo {

 

      // method that returns information about the variables

      // GuestBookTag creates for use in a JSP

      public VariableInfo [] getVariableInfo( TagData tagData )

      {

VariableInfo firstName = new VariableInfo( "firstName",

"String", true, VariableInfo.NESTED );

                 

      VariableInfo    lastName = new VariableInfo( "lastName",

      "String", true, VariableInfo.NESTED );

                 

      VariableInfo email = new VariableInfo( "email",

      "String", true, VariableInfo.NESTED );

                 

      VariableInfo varableInfo [] =

      { firstName, lastName, email };

                 

      return varableInfo;

      }

      }

 

Fig. 31.38 GuestBookTagExtraInfo used by the container to define scripting variables in a JSP that uses the guestlist custom tag.

      <!--      A tag that iterates over an ArrayList of GuestBean -->

      <!--      objects, so they can be output in a JSP           -->

    <tag>

    <name>guestlist</name>

 

    <tagclass>

    com.deitel.advjhtp1.jsp.taglibrary.GuestBookTag

    </tagclass>

      <teiclass>

      com.deitel.advjhtp1.jsp.taglibrary.GuestBookTagExtraInfo

      </teiclass>

          <bodycontent>JSP</bodycontent>

 

      <info>

      Iterates over a list of GuestBean objects

      </info>

</tag>

 

Fig. 31.39  Element tag for the guestlist custom tag.

 

 

To test customTagBody.jsp in Tomcat, copy customTagBody.jsp and the updated advjhtp1-taglib.tld into the jsp directory created in Section 31.3. Copy

 

GuestBookTag.class and GuestBookTagExtraInfo.class into the advjhtp1 Web application’s WEB-INF\classes directory in Tomcat. [Note: This example will work only if the proper package directory structure for GuestBookTag and GuestBookTagExtraInfo is defined in the classes directory.] Open your Web browser and enter the following URL to test customTagBody.jsp:

 

http://localhost:8080/advjhtp1/jsp/customTagBody.jsp

 

 

This chapter has presented many JSP capabilities. However, there are additional fea-tures that are beyond the scope of this book. For a complete description of JavaServer Pages, see the JavaServer Pages 1.1 specification, which can be downloaded from java.sun.com/products/jsp/download.html. Other JSP resources are listed in Section 31.9.


Study Material, Lecturing Notes, Assignment, Reference, Wiki description explanation, brief detail


Copyright © 2018-2020 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.