Using the HTML Tag Library

 < Day Day Up > 

To use the HTML Tag Library in a Struts application, you need to include the following snippet in your Web Archive (.war) deployment descriptor, web.xml:

<taglib>   <taglib-uri>/WEB-INF/tlds/struts-html.tld</taglib-uri>   <taglib-location>/WEB-INF/tlds/struts-html.tld</taglib-location> </taglib> 

Remember from the overview of the web.xml file in Chapter 2 that the <taglib-uri> tag declares the URI (or alias) that will be referenced in each of your JSPs with a taglib directive. The <taglib-location> tag declares the actual location of the Tag Library Descriptor (.tld) file in your Web Archive.

The following snippet illustrates how your JSPs will declare their use of the HTML Tag Library with a JSP taglib directive:

<%@ taglib uri="/WEB-INF/tlds/struts-html.tld" prefix="html" %>

Notice that the uri attribute specified here is the same as that declared with the <taglib-uri> tag in the web.xml file. Also, notice that the prefix attribute is set to “html”. This attribute can be set to whatever you want; however, “html” is the accepted default for the HTML Tag Library. The prefix attribute declares the prefix that each tag must have when it is used in the JSP, as shown here:

<html:html action="/logon">

Because “html” was defined as the prefix, the form tag was used as shown. However, if you chose to use a prefix of “strutshtml”, the tag would be used the following way:

<strutshtml:form action="/logon">

 < Day Day Up > 

Struts. The Complete Reference
Struts: The Complete Reference, 2nd Edition
ISBN: 0072263865
EAN: 2147483647
Year: 2003
Pages: 134
Authors: James Holmes © 2008-2017.
If you may any questions please contact us: