Monday, October 19, 2009

Using the Bean Tag Library













Using the Bean Tag Library


To use the Bean Tag Library in your Struts application, your application's JSPs must declare their use of the library with a JSP taglib directive:



<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>


Notice that the prefix attribute is set to "bean." This attribute can be set to any value; 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"/>





Note 

Modern application servers use the uri attribute of the taglib directive to automatically resolve the location of the tag library descriptor file. Older application servers that support only JSP version 1.1 and/or version 1.0 require that tag libraries be registered in the web.xml file so that they can be resolved, as shown here:



<taglib>
<taglib-uri>http://struts.apache.org/tags-bean</taglib-uri>
<taglib-location>/WEB-INF/tlds/struts-bean.tld</taglib-location>
</taglib>















No comments:

Post a Comment