JSP/Servlet | JSTL(JSP Standard Tag Library) | Basic Functions
JSTL provides several basic functions for development convenience. This section explains those basic functions.
Directive declaration
To use the basic functions, declare the following directive at the top of the JSP page.
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
Functions
| Function | Return value | Usage | Description |
|---|---|---|---|
| contains | boolean | fn:contains(A, B) | Checks whether string A contains string B. |
| containsIgnoreCase | boolean | fn:containsIgnoreCase(A, B) | Checks whether A contains B without case sensitivity. |
| endWith | boolean | fn:endWith(A, B) | Checks whether string A ends with B. |
| escapeXml | String | fn:escapeXml(A) | If A contains strings defined in XML or HTML, converts them to entity codes. |
| indexOf | int | fn:indexOf(A, B) | Returns the first index where B appears in string A. |
| join | String | fn:join(A[], B) | Converts string array A into one string using B as the delimiter. |
| length | int | fn:length(A) | Returns the total length of a Collection object such as List or ArrayList. |
| replace | String | fn:replace(A, B, C) | Finds characters matching B in string A and replaces them with C. |
| split | String[] | fn:split(A, B) | Splits A by the string specified by B and returns an array. |
| startsWith | String | fn:startsWith(A, B) | Checks whether string A starts with B. |
| substring | String | fn:substring(A, B, C) | Returns the substring of A from index B to C. |
| substringAfter | String | fn:substringAfter(A, B) | Returns the substring after B appears in A. |
| substringBefore | String | fn:substringBefore(A, B) | Returns the substring before B appears in A. |
| toLowerCase | String | fn:toLowerCase(A) | Converts all of A to lowercase. |
| toUpperCase | String | fn:toUpperCase(A) | Converts all of A to uppercase. |
| trim | String | fn:trim(A) | Removes leading and trailing whitespace from string A. |
Usage example
toLowerCase, toUpperCase
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<html>
<head>
<title>JSTL Functions</title>
</head>
<body>
<c:set var="str" value="My name is DevKama"/>
<p>Lower Case : ${fn:toLowerCase(str)}</p>
<p>Upper Case : ${fn:toUpperCase(str)}</p>
</body>
</html>
Output result
my name is devkama
MY NAME IS DEVKUMA