The intent of the early JSP specification group members was to define a set of standard JSP tags within the specification. This would allow vendors to generate their own versions of the standard tags but also allow developers to count on this set of standard tags to be available in all compliant containers. However, due to time constraints, that feature of the early JSP specification was not included.
Since then, many vendors have created their own versions of commonly used tag libraries, but these versions are different enough that developers can't easily port their JSP pages from one container to another without having to modify the pages. JSR 52, the JSP Standard Tag Library (JSTL), aims to fix that problem.
JSR 52 defines a set of standard tags that should be present in any compliant container. The first version of the specification has been finalized and approved, and the group has released a reference implementation of the tag library.
The tags provided in the first release can be grouped into four distinct areas:
· Core tags
· Internationalization tags
· XML tags
· SQL tags
The core tags include those related to expressions, flow control, and a generic way to access URL-based resources whose content can then be included or processed within the JSP page. They include tags such as if, forEach, import, redirect, and many more.
The internationalization tags are divided into two groups: messaging and formatting.
The messaging tags assist page authors with creating messages that can be adapted to any locale available in the JSP container. They include tags such as bundle and message.
The formatting tags allow various data elements, such as numbers, currencies, dates, and times, to be formatted and parsed in a locale-sensitive manner. They include tags such as formatDate, parseNumber, and timeZone.
The JSTL XML tag library includes tags that allow XML documents to be accessed. The tags are based on XPath. The XML tags use XPath as a local expression language.
The JSTL SQL tags allow direct access to JDBC resources. They are designed for quick prototyping and simple applications. For larger, more advanced applications, database operations should not be present in the presentation layer—they are normally performed in the model layer. This helps to ensure separation of responsibility.
The tags within the JSTL SQL library include tags for configuring the JDBC resource as well as for querying and updating the database.
JSTL will also introduce a new expression language (EL) to make it easier for page authors to access application data without forcing them to learn a full-fledged programming language like Java. The EL will eventually be part of JSR 152 (the JSP 1.3 specification), but it has been included with JSTL to ensure that a specification is available for the JSTL schedule. The two groups are working closely together so that the EL fulfills both sets of needs.
The JSTL tag libraries come in two versions. One version, known as the JSTL-RT, will continue to support expressions as they are used today. The second version, known as JSTL-EL, will support the new expression language. Both versions will be supported.
For more information on the EL, refer to the JSTL 1.0 specification, which can be downloaded from http://jcp.org/jsr/detail/52.jsp.
JSTL requires a servlet container that supports the Servlet 2.3 specification and Version 1.2 of the JSP specification. If you are using a container that doesn't support these specifications, you will not be able to use JSTL. Tomcat is one container that supports both, but there are many more. Make sure to check with your vendor before attempting to use JSTL.
The Struts Bean and Logic tag libraries may eventually be phased out in favor of the JSTL tags. In the next few versions of the Struts framework, look for changes in these two libraries to help ease that migration.
It should be obvious from looking at the tags included with JSTL that not all of the Struts tags are being replaced. The tags within the HTML tag library in particular will be around for some time.