Introducing to JSP Standard Tag Library

JSP is designed for the presentation layer in the web applications but it needs to contain the logic or code inside the page to control the way it presents the visual elements.

Since JSP was invented, scriptlet has been used intensively, therefore, the JSP pages become messy and difficult to maintain. The HTML mixed with JSP scriptlet and opening and closing brace make JSP page even hard to extend.

In June 2002, JavaServer Pages standard library (JSTL) specification 1.0 was first released.  JSTL provided new ways for JSP author to work with different elements with standard friendly tags. The current version of the JSTL is 1.2 which was started in 2004 so we will use JSTL 1.2 for all the tutorials.

JSP standard tags library can be divided into four tag libraries as follows:

  1. Core tags
  2. Internationalization (i18l) and formatting tags
  3. Relational database access tags
  4. XML processing tags

The goals of those tag library above are:

  • Simplify the task of writing JSP page by providing friendly XML base tags
  • Provide reusable logic from page’s presentation
  • Make the JSP page easier to read and maintain

Core tags

As its name implies, core tags provide the core functionality actions to JSP to make the most common actions easier to achieve in a more effective way. Core tags specify several actions such as displaying content based on condition, manipulating collections and URL managing. By using the core tags you’ll never have to write such small piece of scriptlet. (But you still need to know scriptlet to maintain legacy web applications and convert them to JSTL later on if you have to).

Internationalization(I18L) and formatting tags

Those tags specify a series actions to make the web application multilingual. Those actions including managing resource bundle, locales and base names.

Relational database access tags

Accessing database is a most major task of web applications. JSTL provides a list of standard tags to help you to manipulate data such as select, insert, update and delete from the relational databases.

XML processing tags

XML becomes a standard of enterprise web application for exchanging data. Manipulate XML effectively, therefore, is very important for most web applications and of course JSTL also provides a list of tags for processing from XML parsing to XML transformation.

Let’s take a look at an example how we achieve the same JSP page with scriptlet and JSTL.

As you can see the JSP page with JSTL looks more readable than the JSP page with scriptlet. You’ll those tags in the next tutorials.

  • Was this tutorial helpful ?
  • YesNo