Tag Libraries Included with Struts

The Struts framework provides a fairly rich set of framework components. It also includes a set of tag libraries that are designed to interact intimately with the rest of the framework. The custom tags provided by the Struts framework are grouped into four distinct libraries:

  • HTML

  • Bean

  • Logic

  • Template

There also is a fifth special library, called the Nested tag library, that we’ll talk about separately later in this chapter.

Tip

Earlier versions of the Struts framework contained a tag library called Form. It was replaced with the HTML tag library several versions ago, but form tags still sometimes show up in the documentation or example applications.

The tags within a particular library perform similar or related functions. For example, the tags within the HTML tag library are used to render HTML presentation components inside HTML forms. There’s a tag to generate a checkbox, another for a button, and yet another to generate a hyperlink.

Using Tag Libraries with Struts Applications

There’s nothing special about using the Struts tags—they are like any other JSP custom tags. You must include the TLD declarations for each tag library you use in every page in which you need to use them. If you need to use the HTML and Logic tag libraries in a JSP page, for example, insert the following two lines at the top of the JSP page:

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

Once these lines are included and your web application deployment descriptor contains the necessary taglib elements, you can use the HTML and Logic tags within your JSP page. Continuing with the previous example, you need to add the following lines to your web.xml file:

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

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

For more information on configuring the deployment descriptor for the web application, see Section 4.5 in Chapter 4.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.206.25