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.
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.
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).
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:
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" %>
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.
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" %>
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.
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" %>
prefix="fn" %>
Very useful JSTL tags. Most are used in
conjunction with JSTL core tags. These tags are designed for manipulating
string.
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" %>
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.
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.
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\
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.
like ‘eq’, ‘ne’, ’==’, ’null’, ’empty’, ’not’, ’!=’, ’>=’, ’<=’, ’and’, ’&&’,
’or’, ’||’ all are valid.
Here is the mapping of relational and
logical operators with JSP Notations.
logical operators with JSP Notations.
Operators | JSP Notation |
> | gt |
< | Lt |
>= | ge |
<= | le |
== | eq |
!= | ne |
&& | and |
|| | or |
! | not |
‘’ | empty |
/ | div |
% | mod |
-, and * can also be used together with the JSTL tag as well.
Join my groups to share knowledge at
http://groups.google.com/group/rjetla?hl=en
http://rjetla.blogspot.com/
Thanks & Regards
l¯¯l)¯¯)
l__l\__\aju
. l¯¯l
(¯¯(/__/etla
"falling down is not a crime, staying down is a crime"
http://groups.google.com/group/rjetla?hl=en
http://rjetla.blogspot.com/
Thanks & Regards
l¯¯l)¯¯)
l__l\__\aju
. l¯¯l
(¯¯(/__/etla
"falling down is not a crime, staying down is a crime"
No comments:
Post a Comment