Although I’ve used JSP extensively for quite sometime, I didn’t realize until recently that JSTL supports 16 string functions within the EL syntax. Here is an example JSP page that exercises the 16 string functions…
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<html><body>
contains() --> ${fn:contains('Hello', 'el')}<br>
containsIgnoreCase() --> ${fn:containsIgnoreCase('HELLO', 'el')}<br>
endsWith() --> ${fn:endsWith('Hello', 'llo')}<br>
escapeXml() --> ${fn:escapeXml('1<>3')}<br>
indexOf() --> ${fn:indexOf('Hello', 'el')}<br>
join()/split() --> ${fn:join(fn:split('/1/2/3/4/5', '/'), ':')}<br>
length() --> ${fn:length('Hello')}<br>
replace() --> ${fn:replace('Hello', 'H', 'J')}<br>
startsWith() --> ${fn:startsWith('Hello', 'He')}<br>
substring() --> ${fn:substring('Hello', 2, 4)}<br>
substringAfter() --> ${fn:substringAfter('Hello', 'el')}<br>
substringBefore() --> ${fn:substringBefore('Hello', 'el')}<br>
toLowerCase() --> ${fn:toLowerCase('HELLO')}<br>
toUpperCase() --> ${fn:toUpperCase('hello')}<br>
trim() --> ${fn:trim(' hello ')}<br>
</body></html>
This outputs the following…
contains() --> true
containsIgnoreCase() --> true
endsWith() --> true
escapeXml() --> 1<>3
indexOf() --> 1
join()/split() --> 1:2:3:4:5
length() --> 5
replace() --> Jello
startsWith() --> true
substring() --> ll
substringAfter() --> lo
substringBefore() --> H
toLowerCase() --> hello
toUpperCase() --> HELLO
trim() --> hello
You can see the full reference for these string functions here. This requires JSP 2.0.
You can also find an excellent article on creating a custom JSP function here.