Wednesday, 22 June 2011

Tag Lib Imports for JSPs

Yesterday I mentioned that I favoured a mixture of different JSP tag libraries, which has come about for no other reason than convenience, which were Spring, JSTL and Struts. Having said that I thought about why I use them and the features I use from each one.

From the Spring tag-lib I use the form tag because it integrates with Spring’s MVC technology binding your data entry forms tightly to your Spring Java code, and the spring tag for property display via resource bundles - amongst other things.

To include the Spring form tag in your JSP use the following:

<%@ taglib prefix="form" uri=""%>

To include the Spring spring tag in your JSP then use the following:

<%@ taglib uri="" prefix="spring"%>

I tend to use the tiles part of the Struts tag-lib (although it contains a lot of other functionality), because my screens are structured using tiles for re-usability.

To import the struts tiles tag-lib use the following:

<%@ taglib prefix="tiles" uri="" %>

My final tag lib of choice is the JSTL tag lib. This contains useful, basic programming paradigms such as looping and decision making.

To import the JSTL tag-lib use the following line of code in your JSP:

<%@ taglib prefix="c" uri=""%>

Spring tab libraries are fully explained on the Spring web site in their reference manual.

No comments: