Java Reference
In-Depth Information
Defining a Tag
The tag handler class (CrtEmpBean) has been created but the tag has not yet been defined. A tag is defined in a tag
library. A tag library is a file with an extension of tld (tag library descriptor) that contains XML (Extensible Markup
Language). XML is fast becoming the glue that holds the Internet together. XML is a markup language just like
HTML is a markup language. However, HTML is limited to defining Web pages. XML can be used to define any type
of information: data, documents, file locations, etc. Really, XML is a language that allows a programmer to define a
language. However, we will be using XML in a much more limited capacity.
In the case of a tag library, the server expects the XML to identify a tag and its associated tag handler class. There
are other optional XML statements and we will look at one of these later in the chapter. The server also requires that
the tag library file (of type tld) be in the WEB-INF folder.
Tutorial: Defining a Tag
Let's define a tag:
1.
In the Project Explorer, expand the WebContent folder and select WEB-INF.
2.
Click on File, New, and then Folder.
3.
At the New Folder window, specify tls as the Folder name.
The folder tls should appear in the Enterprise Explorer and be selected.
4.
Click on File, New, and then File. (If File isn't an option, select Other, expand the Simple
option, select File, and then click the Next button.)
5.
In the file name, specify TNT.tld and click the Finish button.
RAD will display the empty file.
6.
Enter the following XML:
<taglib>
<tag>
<name>getEmp</name>
<tagclass>c11.CrtEmpBean</tagclass>
</tag>
</taglib>
This defines the tag (getEmp) and the tag handler (c11/CrtEmpBean) that will be run by the server when the tag
is encountered.
7.
Save TNT.tld
8.
In EnterEmpInfoJSP source code, add the following taglib directive before the existing
JSTL core taglib directive:
<%@taglib uri="/WEB-INF/tls/TNT.tld" prefix="TNT"%>
9.
In EnterEmpInfoJSP, replace the following tags:
<jsp:useBean id="EmpBean" class="c9java.Employee" scope="request">
<jsp:setProperty name="EmpBean" property="empNum" param="empNumTF" />
<jsp:setProperty name="EmpBean" property="empStreet"
param="streetAddrTF"/>
 
Search WWH ::




Custom Search