Page 1 of 8
Introduction
The latest version of
JSTL is JSTL 1.1. Without any hesitation, JSTL is now extremely important in ensuring
the success of the J2EE web application projects. JSTL is basically part of JSP
2.0 specification and requires Java Servlet 2.4 and higher to support its tags.
After completing this
tutorial, you are expected to be able to apply JSTL technology to your JSP, know
what are JSTL tags, know how and when to use certain tags under certain
circumstances according to your needs.
Specifics Information on JSTL and Netbeans
This tutorial has been
compiled, tested and run under:
- Netbeans 5.5
- JSTL 1.1 library package
- Tomcat 5.5.7 as server
If you have installed
NetBeans successfully, JSTL library (.jar) can be found on your local hard
disk. It is bundled together with Netbeans. For your information, it can be
found in: netbeans_installation_folder\enterprise1\config\TagLibraries\JSTL11
You
can also download JSTL taglib library from Jakarta apache project online website on http://jakarta.apache.org/builds/jakarta-taglibs/releases/standard/binaries/.
Some included jar for JSTL 1.1 library are jaxen-full.jar, jstl.jar, saxpath.jar,
standard.jar, xalan.jar. However, only jstl.jar and standard.jar are required. So
why do we need those other jar files? Well, standard.jar depends on other jars
like xalan.jar, saxpath.jar, dom.jar, etc to work properly. You can use J2SE
1.4.2 and higher to avoid these dependencies. However, as the JSTL taglib
library has been bundled together with the NetBeans, you do not need to
download it anymore.
Roadmap
- What is JSTL?
- Why use JSTL?
- Implementation of JSTL Core
Tags
- Implementation of JSTL
Formatting Tags
- Implementation of JSTL
Function Tags
- Conclusion
- Appendix
1. What is JSTL?
JSTL stands for JSP
Standard Tag Library. JSTL has been standardized and is being one of the most
important technologies in implementing J2EE Web Application. The main objective
of the JSTL is basically to simplify the Java codes within JSP (scriptlets) as
well as to increase the level of reusability within our J2EE web application. Before
JSTL is introduced, J2EE Web Applications (especially in the presentation layer
� JSP) are extremely complex and are very tough to be maintained. It is true
that the new developer may take some time to understand all the underlying
codes within J2EE Web Application This is where JSTL should help.
Here is a simple JSTL flow concept; JSTL is
compiled into a servlets (Java codes) before being displayed to JSP. Some
classes of standard.jar are required to parse and translate these JSTL tags
into servlets (Java codes). Lastly but not least, the servlet that has been
compiled will be executed accordingly.
There are many more advantages
of using JSTL compared to scriptlets. Therefore, it is recommended to replace
scriptlets with JSTL in the presentation layer (JSP).
There
are 5 major types of JSTL tags:
- JSTL Core tags,
prefixed with c
- JSTL Format tags,
prefixed with fmt
- JSTL Function
tags, prefixed with fn
- JSTL Database
tags, prefixed with sql
- JSTL XML tags,
prefixed with x
JSTL Core Tags
<%@ taglib
uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
Mainly used for replacement of scriptlet logical
tags as well as basic URL handling tag such as catch, choose, if, forEach,
param, when, redirect, import, url, etc.
JSTL Format Tags
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt"
prefix="fmt" %>
Mainly used for displaying number and date time format. This could be
used for internationalization support as well. Tags examples are setLocale,
setTimeZone, setBundle, formatNumber, formatDate, etc.
JSTL Function Tags
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions"
prefix="fn" %>
Very useful JSTL tags. Most are used in
conjunction with JSTL core tags. These tags are designed for manipulating
string.
JSTL Database Tags
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql"
prefix="sql" %>
Tags are used to interact with database level. With database tags you
could do transaction, update and query the database from your UI level.
Personally, I do not prefer these tags. The MVC design pattern should always be
retained.
JSTL XML tags
<%@ taglib uri="http://java.sun.com/jsp/jstl/xml" prefix="x"
%>
Similar to core tags, except xml tags will
deal with xml stuffs like parsing xml documents, validating xml documents, output
an xpath and etc.
For depth details to all JSTL tags, you can
find more information within your NetBean�s installation folder i.e. installation_netbeans_folder\enterprise1\docs\
Additionally, JSTL accepts the conditional operators
like �eq�, �ne�, �==�, �null�, �empty�, �not�, �!=�, �>=�, �<=�, �and�, �&&�,
�or�, �||� all are valid.
Here is the mapping of relational and
logical operators with JSP Notations.
Operators
|
JSP
Notation
|
>
|
gt
|
<
|
Lt
|
>=
|
ge
|
<=
|
le
|
==
|
eq
|
!=
|
ne
|
&&
|
and
|
||
|
or
|
!
|
not
|
��
|
empty
|
/
|
div
|
%
|
mod
|
While other arithmetic operators such as +,
-, and * can also be used together with the JSTL tag as well.
<< Start < Prev 1 2 3 4 5 6 7 8 Next > End >> |
You can share your information about this topic using the form below!
Please do not post your questions with this form! Thanks.