Home arrow JavaScript arrow Page 2 - JSTL: Getting Started
JAVASCRIPT

JSTL: Getting Started


The JSP Standard Tag Library, or JSTL for short, is a standardized set of custom tags used in Java that can save programmers a lot of time and trouble. This article explores the basics of the JSTL.

Author Info:
By: A.P.Rajshekhar
Rating: 5 stars5 stars5 stars5 stars5 stars / 13
June 20, 2006
TABLE OF CONTENTS:
  1. · JSTL: Getting Started
  2. · JSTL: Understanding the Terminology
  3. · JSTL: Understanding the Types
  4. · JSTL in the Real World

print this article
SEARCH DEVARTICLES

JSTL: Getting Started - JSTL: Understanding the Terminology
(Page 2 of 4 )

Each new technology brings a host of new terminology with it. JSTL is no exception. Having custom tags as its base, JSTL has eased the terminology aspect a bit, yet there are new additions to the vocabulary of custom tags. These additions can be broadly divided into two groups, which are based on Expression Language and Tag Attributes. The Expression Language related terminology deals with how to manipulate the data at View, whereas the Tag Attribute related terms deal with passing the data to the tag for presentation.

Expression Language

Expression language or EL is the single most important feature of JSTL because it reduces the need to specify tag attribute values with scriptlets. In addition to this, EL provides a universal approach for accessing all sorts of application data including beans, arrays, lists, maps, cookies, request parameters and so on. The services that essentially EL provides are:

  • Expression and identifiers
  • Arithmetic, logical and relational operators
  • Automatic type coercion
  • Universal data access approach

Of these, the first two are only syntactically different from what we have been doing in scriptlets, whereas the last two are new to EL.

  1. Expression and identifiers. In EL expressions are invoked using the ${expr}syntax, where the expression to be invoked and evaluated is represented by expr. To make this more clear, let me contrast between the EL and scriptlet way of passing values to the tag attributes. In scriptlets the only way to pass data to the attribute involves using Java code. For example, if the value of a string variable tr has to be passed to the attribute value of a tag out with the prefix ex, the syntax would be:

      <ex:out value="<%=str%>"/>

    This in turn means that even if custom tags try to reduce the Java code within JSP, passing the value in such a way undermines the philosophy behind custom tags. The same thing can be done in a much easier way using EL thus:

      <ex:out value="${str}"/>

    In EL identifiers are the name of objects stored in scope, where scope can be page, request, session or application. The default scope is request. In the above example str is an identifier.
  2. Arithmetic, logical and relational operators. In the case of these operators EL has made no changes. As with scriptlets, the expression can contain logical, arithmetic or relational operators. So the following EL expression is completely valid:

      <ex:out value="${1+2}"/>
  3. Automatic type coercion. To change one type of data into another, explicit typecasting must be done in scriptlets. For example, if the attribute expects an int value and the data to be passed is a string value, then the code would be:

      <ex:set value="<%Integer.parseInt(str)%>"/>

    Whereas in EL it would be:

      <ex:set value="${str}"/>

    Here EL does the type conversion implicitly with the developer not required to keep tabs on it. The most dreaded exception for any programmer in the case of a tag is a null value exception. With EL this dread need not exist because EL converts the null strings into empty strings and null values into 0.
  4. Universal data access approach. Accessing data is one of the tough jobs for a Java programmer due to the fact that different members of the collection framework requires different types of access mechanisms. List based classes use index based access, whereas map based classes use key based access. To make the data access universal, EL has provided a bean based access mechanism along with all other types. The bean based access makes it possible to access collections just as one would access a bean's properties. This access is even extended to headers, request parameters and cookies. For example, to access a parameter named lastName from the request scope the EL would be:

      <ex:out value="param.lastName"/>

    Here the term param is a keyword representing the parameters passed as a part of request.

Tag Attributes

JSTL shares many commonalities with the HTML tags. Apart from the syntactical similarity, the attributes share the same name and functionality across different tags. The following list includes the attributes that are common in names and functionalities:

  • value: This attribute takes the value that must either be displayed or passed on to another tag by using the var attribute.
  • var: When the passed value must be set in scope or used by another tag, this attribute comes into the picture. The value passed to this attribute is used as a part of an expression in the next tag. 
  • items: This attributes comes in handy when working with collections. It takes the name of the collection. The name can be the key of the parameter map or the key of the key/value pair set in the session.

These are the three main attributes that are used by different tags for the same  purpose.

So that covers the terminology regularly used in JSTL. In the next section I will be discussing the various tags available as part of JSTL.


blog comments powered by Disqus
JAVASCRIPT ARTICLES

- Project Nashorn to Make Java, JavaScript Wor...
- JavaScript Virus Attacks Tumblr Blogs
- Google Releases Stable Dart Version, JavaScr...
- Khan Academy Unveils New JavaScript Learning...
- Accessing Nitro? There`s an App for That
- JQuery 2.0 Leaving Older IE Versions Behind
- Fastest JavaScript Engine Might Surprise You
- Microsoft Adjusting Chakra for IE 10
- Brendan Eich: We Don`t Need Google Native Cl...
- An Overview of JavaScript Statements
- An Overview of JavaScript Operators
- Overview of JavaScript Variables
- More of the Top jQuery Social Plugins
- The Top jQuery Social Plugins
- More of the Top jQuery Slider Plugins

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2019 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials