Skip to main content

JSTL Tutorials Using NetBeans : Part-1

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:
  1. Netbeans 5.5
  2. JSTL 1.1 library package
  3. 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
  1. What is JSTL?
  2. Why use JSTL?
  3. Implementation of JSTL Core Tags
  4. Implementation of JSTL Formatting Tags
  5. Implementation of JSTL Function Tags
  6. Conclusion
  7. 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:
  1. JSTL Core tags, prefixed with c
  2. JSTL Format tags, prefixed with fmt
  3. JSTL Function tags, prefixed with fn
  4. JSTL Database tags, prefixed with sql
  5. 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.

Comments

Popular posts from this blog

Asynchronous Vs. Synchronous Communications

Synchronous (One thread):   1 thread -> |<---A---->||<----B---------->||<------C----->| Synchronous (multi-threaded):   thread A -> |<---A---->| \ thread B ------------> ->|<----B---------->| \ thread C ----------------------------------> ->|<------C----->|

WebSphere MQ Interview Questions

What is MQ and what does it do? Ans. MQ stands for MESSAGE QUEUEING. WebSphere MQ allows application programs to use message queuing to participate in message-driven processing. Application programs can communicate across different platforms by using the appropriate message queuing software products. What is Message driven process? Ans . When messages arrive on a queue, they can automatically start an application using triggering. If necessary, the applications can be stopped when the message (or messages) have been processed. What are advantages of the MQ? Ans. 1. Integration. 2. Asynchrony 3. Assured Delivery 4. Scalability. How does it support the Integration? Ans. Because the MQ is independent of the Operating System you use i.e. it may be Windows, Solaris,AIX.It is independent of the protocol (i.e. TCP/IP, LU6.2, SNA, NetBIOS, UDP).It is not required that both the sender and receiver should be running on the same platform What is Asynchrony? Ans. With messag...

Advantages & Disadvantages of Synchronous / Asynchronous Communications?

  Asynchronous Communication Advantages: Requests need not be targeted to specific server. Service need not be available when request is made. No blocking, so resources could be freed.  Could use connectionless protocol Disadvantages: Response times are unpredictable. Error handling usually more complex.  Usually requires connection-oriented protocol.  Harder to design apps Synchronous Communication Advantages: Easy to program Outcome is known immediately  Error recovery easier (usually)  Better real-time response (usually) Disadvantages: Service must be up and ready. Requestor blocks, held resources are “tied up”.  Usually requires connection-oriented protocol