JSP Standard Tag Library Tutorial (JSTL), JSTL Tags

  • JSTL stands for JSP Standard Tag Library.
  • It can be used only in JSP pages.
  • JSTL tag can be used for conditional, iteration tags for manipulating the XML document, internationalization tags, and SQL tags.
  • It is used to remove scriptlet code from a JSP page.

Advantages of JSTL

  1. Fast Development: we can provide many tags which simplify the JSP.
  2. Code Reusability: Use the JSTL tags on the previous page.
  3. It avoids the scriptlet tag.

Types of tags in JSTL

1. Core tags
2. Formatting tags
3. Function tags.
4. XML tags
SQL tags

1. JSTL Core Tags:

JSTL Core tags include those which are related to variables, and flow control, as well as it is a generic way to access URL based resources.
The following are the JSTL Core tags:

i) c:out: 

it is used to display the result of an expression. It is just like an expression tag.

ii) c:set: 

It is used to set the value of a variable in a specified scope.

iii) c:remove: 

This JSTL core tag is used to remove an attribute from a specified scope or from all scope.

iv) c:catch:

It is used for exception handling in JSP.

v) c:forEach: 

It is used for iteration. It is just like for loop in java.

vi) c:param:

 It is used to add a parameter and their values to the output of these tags.

vii) c:redirect: 

It is used for redirecting the current page to another URL.

viii) c:url:

To rewrite URL returned from a JSP page, we can use url tag.

ix) c:if:

 It is used to testing the condition. It is just like to if statement in java.

x) c:import:

It is used for importing the content from another file/page to the current JSP page.

2. JSTL Formatting tags:

JSTL formatting tags are used to formatting the text, date, number, etc. The JSTL Formatting tags are also used to formatting the date, and time of internationalization websites.
The following are the JSTL Formatting Tags:

i) fmt:timeZone: 

It specifies the time zone for any time formatting or parsing action nested in its body.

ii) fmt:setTimeZone: 

Stores the given time zone in the time zone configuration variable.

iii) fmt:formatDate: 

Formats a date and/or time using the supplied styles and pattern.

iv) fmt:message: 

used to display an internationalized message.

v) fmt:formatNumber: 

It is used to render numerical value with a specific precision or format.

vi) fmt:parseNumber: 

Parses the string representation of number, currency, or percentage.

vii) fmt:parseDate: 

Parses the String representation of the date and/or time.

viii) fmt:bundle:

Load a resource bundle to be used by its tag body.

ix) fmt:setBundle: 

Loads a resource bundle and stores it in the named scoped variable or the bundle configuration variable.

3. JSTL Function tags:

This tag provides a number of predefined function that can be used to perform a common operation such as String concatenation, String split etc. It is used for String manipulation.

The following are the JSTL Function Tags:

i) fn:contains():

It tests if an input string contains the specified substring.

ii) fn:containsIgnoreCase(): 

It tets if an input string contains the specified substring in a case-insensitive way.

iii) fn:endsWith():

It tets if an input string ends with the specified suffix.

iv) fn:indexOf():

Return the index writing a string of the first occurrence of the specified string.

v) fn:join():

It joins all the elements of an array into a String.

vi) fn:length(): 

It returns the number of character in a String or number of collection in a String.

vii) fn:replace(): 

It is used to replacing an input string all occurrences with the given String.

viii) fn:split(): 

Split a string into an array of a substring.

ix) fn:startsWith():

It tests if an input string starts with the specified prefix.

x) fn:substring():

It returns a subset of a string

xi) fn:substringAfter():

It returns a subset of a String after a specific substring.

xii) fn:substringBefore(): 

It returns a subset of a String before a specific substring.

xiii) fn:toLowerCase():

It converts all of the characters of a string to lower case.

xiv) fn:toUpperCase():

It converts all of the characters of a string to upper case.

xv) fn:trim ():

It removes white spaces from both ends of a string.

4) JSTL XML Tags:

JSTL XML Tags are used to work with XML documents.It is used for manipulating and creating XML document. It provide flow control, Transformation etc.
The following are the JSTL XML Tags:

i) x:out:

It evaluates the expression of XPath. It is just Like <%=   %>, but for XPath expression.

ii) x:parse:

It is used to parse the XML data specified either via an attribute or in the tag body.

iii) x:set:

It sets the value of a variable of an XPath expression.

iv) x:choose:

Subtag of that will include its body if the condition evaluated to be 'true'.

v) x:when:

Subtag of <choose> that includes its body if its expression evaluates to 'true'.

vi) x:otherwise: 

subtag of <choose> that follows the <when> tags and run only if all of the prior condition evaluated to 'false'.

vii) x:if:

It evaluates a test XPath expression and if it is true, it processes its body. If the condition is false, then the body is ignored.

viii) x:param: 

It is used along with the transform tag to set a parameter in the XSLT stylesheet.

ix) x: transform: 

It applies an XSL transformation on a XML document.

5. JSTL SQL Tag:

This tag provides SQL support. It is used for interacting with RDBS(Relational Database Management System) such as MySql, Oracle etc. we can run database queries using SQL tags.

The following are the JSTL SQL Tags:

i) sql:setDataSource: 

It creates a simple data source suitable for prototyping.

ii) sql:query:

It is used to executes the SQL queries defined in its body or through the SQL attribute.

iii) sql:update: 

It executed the SQL update defined in its body or through the SQL attribute.

iv) sql:param: 

It sets a parameter in an SQL statement to the specified value.

v) sql:dateParam: 

It sets a parameter in an SQL statement to the specified java.util.Date value.

vi) sql:transaction: 

It provides nested database action elements with a shared connection, set up to execute all statement  as one transaction

You may also like:
Life Cycle of a JSP Page
9 implicit objects in JSP
JSP Directives - Page, include, and taglib
JSP Action Tags - JSP useBean, JSP include, and JSP forward
MVC Architecture in JSP with Example
JSP Expression Language (EL)
JSP Standard Tag Library Tutorial (JSTL), JSTL Tags JSP Standard Tag Library Tutorial (JSTL), JSTL Tags Reviewed by Prashant Srivastava on December 21, 2018 Rating: 5

No comments:

Powered by Blogger.