Вы находитесь на странице: 1из 30

JSP STANDARD TAG

LIBRARY

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.

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.

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.

CONTINUED

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

CONTINUED

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.

Operators JSP Notation

> gt
< Lt
>= ge
<= le
== eq
!= ne
&& and
|| or
! not
empty
/ div
% mod

WHY USE JSTL?

Advantage of JSTL
Scriptlets (Java codes within JSP) are complex and are
extremely hard to be maintained. Unlike scriptlets, JSTL makes
our JSP readable and maintainable.
HTML programmer may find it hard to modify the JSP with the
scriptlets as he or she may not have the Java programming
knowledge. However, if we are using JSTL to replace our
scriptlets, HTML programmer can easily understand on whats
going on in the JSP as JSTL is in the form of XML tags similar to
the normal HTML tags.
JSTL has been standardized and is reusable tags.
The name of each tag in JSTL is self-explanatory and is easy to
understand.
JSTL requires less code compared to scriptlets.

CONTINUED

Scriptlets provide you with greater flexibility.


As scriptlets is simply a Java codes, you can
do anything that you want as you normally do
with a Java programming. On the other hand,
JSTL is a very specific and each tag has its
own purposes.

Implementation of
JSTL Functional Tags

JSTL Format Tags

Вам также может понравиться