Using the Bean Tag Library

 < Day Day Up > 



To use the Bean Tag Library in your 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-bean.tld</taglib-uri>   <taglib-location>/WEB-INF/tlds/struts-bean.tld</taglib-location> </taglib> 

Remember from the review of the web.xml file in Chapter 2 that the <taglib-uri> tag is used to declare the URI (or alias) that will be referenced in each of your JSPs with a taglib directive. The <taglib-location> tag is used to declare 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 Bean Tag Library with a JSP taglib directive:

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

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 “bean.” This attribute can be set to whatever you want; however, “bean” is the accepted default for the Bean Library. The prefix attribute declares the prefix that each tag must have when it is used in the JSP, as shown here:

<bean:write name="result" property="ssNum"/>

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

<strutsbn:write name="result" property="ssNum"/>



 < Day Day Up > 



Struts. The Complete Reference
Struts: The Complete Reference, 2nd Edition
ISBN: 0072263865
EAN: 2147483647
Year: 2003
Pages: 134
Authors: James Holmes

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net