JavaScript
  Home arrow JavaScript arrow Page 2 - JSTL: Getting Started
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVASCRIPT

JSTL: Getting Started
By: A.P.Rajshekhar
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 8
    2006-06-20

    Table of Contents:
  • JSTL: Getting Started
  • JSTL: Understanding the Terminology
  • JSTL: Understanding the Types
  • JSTL in the Real World

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    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.

    More JavaScript Articles
    More By A.P.Rajshekhar


       · Hi allJSTL provides HTML like tags for almost all the common routines in Java. In...
     

    JAVASCRIPT ARTICLES

    - Using Click Interceptions with a Database-Dr...
    - Using JavaScript Click Interceptions in an I...
    - Using Click Interceptions with JavaScript
    - QuickSort in Action
    - Quicksort
    - Using Mod_Security to Protect Your Server
    - Detecting and Countering Server Intrusions
    - Securing Your Web Server
    - Building a Secure Web Server
    - Protecting the Server
    - Book Review: Learning the Yahoo! User Interf...
    - Dynamically Generate a Selection List in a R...
    - Intergrate DWR into Your Java Web Application
    - Detect Browser Compatibility with the Reques...
    - Using the EXT JS Date Picker Widget






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
    Stay green...Green IT