Using the Java Standard Tag Library (JSTL) in a JSP Page
There are four tag libraries that make up the JSTL; see the
javax.servlet.jsp.jstl.* packages for examples that use these tag
libraries. JSTL is not yet a standard part of a JSP container.
Hence, in order to use the JSTL in a web application, you must include
a copy the JSTL library code in the WEB-INF directory of your web
application. These files are available in the Web Services Developer
Pack, which can be download from
http://java.sun.com/webservices/webservicespack.html.
A tag library has two parts: a Tag Library Descriptor (TLD)
file and a JAR file. The following ant elements copy the TLD files
from the Web Services Developer Pack into WEB-INF/tld and the JAR
files into WEB-INF/lib. These elements should be added to the
build target in your build.xml file:
In order for a JSP page to use the JSTL, it must declare it's
use on the page using the taglib directive. Here's an example
that declares the use of all four JSTL tag libraries:
The tags in the JSTL core tag library can then be referenced using the
specified prefix as in:
See also Enabling the JSTL Expression Language in a JSP Page.
<%-- Copy TLD files from WSDP installation --%>
<copy todir="${build}/WEB-INF/tld">
<fileset dir="${jwsdp.home}/tools/jstl/tld">
<include name="*.tld" />
</fileset>
</copy>
<%-- Copy JSTL jar files from WSDP installation --%>
<copy todir="${build}/WEB-INF/lib">
<fileset dir="${jwsdp.home}/tools/jstl">
<include name="jstl.jar" />
</fileset>
<fileset dir="${jwsdp.home}/tools/jstl/standard/lib">
<include name="standard.jar" />
</fileset>
</copy>
<%-- Core --%>
<%@ taglib uri="/WEB-INF/tld/c-rt.tld" prefix="c_rt" %>
<%-- I18N Formatting --%>
<%@ taglib uri="/WEB-INF/tld/fmt-rt.tld" prefix="fmt_rt" %>
<%-- SQL --%>
<%@ taglib uri="/WEB-INF/tld/sql-rt.tld" prefix="sql_rt" %>
<%-- XML --%>
<%@ taglib uri="/WEB-INF/tld/x-rt.tld" prefix="x_rt" %>
<c_rt:if test='<%= request.getParameter("param") != null %>'>
<%= request.getParameter("param") %>
</c_rt:if>
Post a comment