Starting with JSTL


JSTL

The JSP Standard Tag Library (JSTL) is 
mainly the collection of four custom tag libraries. These custom tag libraries allow developers to use the predefined tags instead of writing the same thing again and again. It is used with JSP pages.

JSTL core tags are :

  1. The core JSTL
  2. The XML Tag library
  3. The Format tag library
  4. The Sql tag library

The Core JSTL: The core tags are used to perform iteration, conditional processing, It can be used in jsp page by accessing the following library:

< %@ taglib prefix="c" uri="http:// java.sun.com/jstl/core" %>

There are mainly three types of core tags:

  1. General purpose tags:  It is used for writing the values to the output stream, and setting and removing attributes.

    • <c:out>: It evaluates an expression that may be given in its value attribute or in its tag body. It shows  the output.

      <c:out attributes> result</c:out>
       
    • <c:set>:It is another  general purpose tag, which allows us to set the value of a variable or property into the given scop.

      <c:set attribute> body</c:set>
       
    • <c:remove>: The <c:remove> tag allows us to remove the variable from the specified. the syntax is:

      <c:remove attributes/>
       
    • <c:catch>: It is used  to allow jsp pages to handle exception that might be raised by any of the tag inside the <c:catch>tag.

      <c:catch attributes>body content</c:catch>
       
  2. Conditional Looping Tags: It tags include conditions, switch cases and loops.

    Types of conditional and looping tags:

    • <c:if>
       
    • <c:choose>
       
    • <c:when>
       
    • <c:otherwise>
       
    • <c:foreach>
       
    • <c:fortoken>
       
  3. Networking Tags: It is used for the including some other web pages and redirecting the client request.

    Types of Networking Tag:

    • <c:import>
       
    • <c:url>
       
    • <c:redirect>
       
    • <c:param>

JSTL SQL Tags : The Sql tag library is used to access the relational  data base used in jsp pages.

Types of SQl Tag:

  1. <sql:query tag>: It executes the query specified in the Sql attribute or in the tag body. Syntax for the query tag:

    <sql:query attributes> body</sql:query>
     

  2. <sql:update tag>: The result of the query is  set to the variable specified in the var attribute.

    <sql:update attributes>body</sql:update>
     

  3. <sql:param tag>:It is used to set a parameter in the Sql statement.

    <sql:param attributes>body</sql:param>
     

  4. <sql:dateparam>: It is used to set a date parameter in the Sql statement.

    <sql:dateparam attributes/>
     

  5. <sql:setDataSource>:It is used for binds a data source to the specified variable.

JSTL Formatting Tags:

The format tag library provides support for internationalization. This provide formating of data in different domain. The data can be numbers, or the time specifications in different domains. It is used as:

<%taglib prefix="fmt:uri="http://java.sun.com/jsp/jstl/fmt" %>

There are four types of JLST formating Tag:

  1. Basic formatting tags

  2. Number formatting tags

  3. Date formatting tags

  4. Time Zone tags

JSTL XML Tags:

The XML Tag library is used to work with XML data used in the jsp pages. The XML tag library helps parse and transform the data used in the jsp page.

The syntax for this tag is:

<%@taglib prefix="x" uri="http://java.sun.com/jsp/jstl/xml" %>

XML tags are also categorized into following categories:

  1. XML Core tags: It include the tags for parsing xml documents and performing operations. There are three types:

    • <x:parse>
       
    • <x:out>
       
    • <x:set>
       
  2. XML Flow Control Tags: It is used for the easily parse and access xml data, iterate over elements in an xml document.

    There are five tags in contains:

    • <x:if>
       

    • <x:choose>
       

    • <x:when>
       

    • <x:otherwise>
       

    • <x:forEach>
       

  3. XML Transformation Tags: This is used for the providing the support to transform the xml document with the given xsl stylsheet. This part also contain two parts:

    • <x:transform>: It tansform an xml document using the given XSL style sheet.

      Syntax : <x:transform attributes>body</x:transform>
       

    • <x:param>: It is used to set transformation parameters. It should be used within the body of the <x:transform>tag.

      Syntax : <x:param attributes> body </x:param>

 Example 1.

Untitled-3.gif
output:

Untitled-1.gif

In this article I have described core and xml tag. For the format tag you may follow the following link:

http://www.c-sharpcorner.com/UploadFile/0d4935/description-of-jstl-formating-tag


Similar Articles