JSTL functions and Core Tags- JSTL(JSP Standard Tag Lib) Tutorial

JSTL stands for JSP standard tag Library which is a collection of very useful core tags and functions. These tags and functions will help you write JSP code efficiently.

JSTL Core Tags

Below is the collection of tutorials on JSTL core tags. Each tutorial is explained with the help of screenshots and proper examples. The following line of statement must be present in your JSP in order to use the JSTL core Tags.

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
  1. <c:out> tag: It is used for displaying the content on client after escaping XML and HTML markup tags. Main attributes are default and escapeXML.
  2. <c:set> tag: This tag is useful for setting up a variable value in a specified scope. It basically evaluates an expression and sets the result in given variable.
  3. <c:remove> tag: It is used for removing an attribute from a specified scope or from all scopes (page, request, session and application). By default removes from all.
  4. <c: if> tag: This JSTL core tag is used for testing conditions. There are two other optional attributes for this tag which are var and scope, test is mandatory.
  5. <c:choose> tag: It’s like switch statement in Java.
  6. <c:when> tag: It’s like case statement in Java.
  7. <c:otherwise> tag: It works like default attribute in switch-case statements.
  8. <c:catch>tag: This tag is used in exception handling. In this post we have discussed exception handling using <c:catch> core tag.
  9. <c:import> tag: This JSTL core tag is used for importing the content from another file/page to the current JSP page. Attributes – var, URL and scope.
  10. <c:forEach> tag: This tag in JSTL is used for executing the same set of statements for a finite number of times.
  11. <c:forTokens> tag: It is used for iteration but it only works with delimiter.
  12. <c:param> tag: This JSTL tag is mostly used with <c:url> and <c:redirect> tags. It adds parameter and their values to the output of these tags.
  13. <c:url> tag: It is used for url formatting or url encoding. It converts a relative url into a application context’s url. Optional attributes var, context and scope.
  14. <c:redirect> tag: It is used for redirecting the current page to another URL, provide the relative address in the URL attribute of this tag and the page will be redirected to the url.

JSTL Functions

Following are the tutorial links for useful JSTL functions with examples. Following Taglib directive should be included in the JSP page in order to use the JSTL functions.

<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
  1. fn:contains function: This function checks whether the given string is present in the input as sub-string. It does a case sensitive check.
  2. fn:containsIgnoreCase(): It does a case insensitive check to see whether the provided string is a sub-string of input.
  3. fn:indexOf(): It is used for finding out the start position of a string in the provided string. Function returns -1 when string is not found in the input.
  4. fn:escapeXML(): It is used for HTML/XML character escaping which means it treats html/xml tags as a string. Similar to the escapeXml attribute of <c:out> tag.
  5. fn:join() and fn:split() functions: JSTL functions: fn:join() concatenates the strings with a given separator and returns the output string. fn:split() splits a given string into an array of substrings.
  6. fn:length(): The JSTL function fn:length() is used for computing the length of a string or to find out the number of elements in a collection. It returns the length of the object.
  7. fn:startsWith(): It checks the specified string is a prefix of given string.
  8. fn:endsWith(): fn:endsWith() JSTL function is used for checking the suffix of a string. It checks whether the given string ends with a particular string.
  9. fn:substring(): This JSTL function is used for getting a substring from the provided string.
  10. fn:substringAfter(): It is used for getting a substring which is present in the input string before a specified string.
  11. fn:substringBefore(): It gets a substring from input which comes after a specified string.
  12. fn:trim(): JSTL Function fn:trim() removes spaces from beginning and end of a string and function.
  13. fn:toUpperCase(): It is just opposite of fn:toLowerCase() function. It converts input string to a uppercase string.
  14. fn:toLowerCase(): This function is used for converting an input string to a lower case string.
  15. fn:replace(): fn:replace() function search for a string in the input and replace it with the provided string. It does case sensitive processing.

To find out more tutorials on JSTL refer the archive here.

More tutorials »

JSP tutorial

7 comments… add one

  • gourav kataria February 27, 2014, 4:18 AM

    hello sir
    plz upload some java awt tutorials

    • Chaitanya Singh April 6, 2014, 3:34 PM

      Hi Gourav, I will publish them soon. Thanks for stopping by :)

  • KV Iyer April 17, 2014, 6:19 PM

    Hi Chaitanya,
    Please upload some Tutorial on Java Server Faces2.0, EJB 3.0, JPA…etc, will be very helpful from your end…

  • Hoshiyar Singh August 19, 2014, 2:54 PM

    Hello Chaitanya Sir,
    website is very very helpful for beginners. you explain each topic
    very clearly and interesting way.
    plz upload EJB & JSF tutorial.


  • deep rathod September 14, 2014, 3:19 AM

    how to Write a program that prints 1 to 10 and 10 to 1 reverse(Use JSTL)

  • vinodhini November 2, 2014, 8:40 AM

    Your tutorial is very useful..very easy to understand ..thank you…

  • mayank September 30, 2015, 1:12 PM

    please upload tutorials on java swing and applets..!


Leave a Comment