Updated March 28, 2023
Introduction to JSTL Tags
JSTL is a JSP Standard Tag Library. JSTL represents a set of a library that is used for JSP development. In this article, we are going to discuss those tags. tags provided by JSTL simplify the JSP development. JSTL tags can be used on various pages, this feature provides code reusability. JSTL tags mostly avoid the use of scriptlet tags.
JSTL Tags
JSTL tags can be categorized into five types:
1. Core tags
2. Function tags
3. Formatting Tags
4. XML tags
5. SQL tags
Let’s discuss all these tags one by one:
1. Core Tags
This JSTL core tags provides support for the variables, manages flow control and URL, etc. The prefix used for core tags is c.
- <c:out> tag: This tag is used to display the result of an expression, similar to the way < %=…% > work.
- <c:import> tag: This tag provides all of the < include > action functionality as well as it allows the addition of absolute URLs.
- <c:set> tag: The outcome of an expression evaluated in a ‘ field ‘ is set with it. The < c: set > tag is useful because the expression is evaluated and the result is used to set a value of java.util.Map or JavaBean.
- <c:remove>: It is used to remove the variable specified from a given scope.
- <c:catch> tag: This tag catches Any Throwable exceptions which occur in the body and optionally exposes. It is used for the handling of errors and solves errors in the program more efficiently.
- <c: if> tag: This Conditional tag used to assess body content, if the condition supplied is true. This used to test the condition, and if the expression evaluated is true, it displays body content.
- <c: choose> tag: It is a conditional tag that sets the context for conditional operations which are mutually exclusive.
- <c:redirect> tag: Using automatic URL rewriting it is used to redirect the browser to an alternate URL.
- <c: param> tag: It adds the parameter to the URL of an import request. It allows us to define the relevant URL request parameter within the URL and will automatically perform any required URL encoding.
- <c:for each> tag: This tag is Used to duplicating nested body content over or over a specified number of times.
2. Function Tags
This JSTL function tag provides support for manipulating string and string length. A prefix used for function tags is fn.
- fn:contains() tag: This tag is used for testing if an input string which contains the fixed substring in a program.
- fn:startsWith() Tag: This tag is used for testing if an input string starts with the specified input value.
- fn:endsWith() tag: This tag is used for testing if an input string ends with the fixed suffix.
- fn:escapeXml() tag: This tag avoids characters interpreted as XML markup.
- fn:indexOf() tag: This tag Returns an index within a string of a defined substring at first occurrence.
- fn:trim() tag: This tag deletes the blank spaces present at both the ends of a string.
- fn:toLowerCase() tag: This tag converts all the characters of a string to lower case.
- fn:toUpperCase() tag: This tag converts all the characters of a string to the upper case.
3. Formatting Tags
This JSTL formatting Tag provides support for formatting string, number, date, etc. A prefix used for formatting tags is fmt.
- fmt:parseNumber tag: This tag is used for Converting the string representation of a percentage, currency, or number.
- fmt:formatNumber tag: This tag is used to format the numerical value with certain format.
- fmt:parseDate tag: This tag is used for Converting the string representation of a date and time.
- fmt:message tag: This tag displays an internationalized message.
- fmt:formatDate tag: This tag formats the date or time using certain patterns.
4. XML Tags
This JSTL XML tag provides support for transformation, flow control, etc. Prefix used for XML tags is x.
- x:parse tag: This tag is used for parse the XML data mentioned in the tag body or specified in an attribute.
- x:set tag: This tag is used for setting a variable to the value of an XPath expression.
- x:if tag: This tag evaluates the test XPath expression and if the expression is true, then it will process its body content.
5. SQL Tags
This JSTL SQL tag provides support for SQL operations. The prefix used for SQL tags is SQL.
- sql:query tag: This tag executes the SQL query specified in its SQL tag body or in the attribute.
- sql:update tag: This tag executing the SQL update specified in its SQL tag body or in the attribute.
Recommended Articles
This is a guide to JSTL Tags. Here we discuss a brief overview on JSTL Tags and its various types along with their brief explanation. You can also go through our other suggested articles to learn more –