The function <fn:startsWith()> is a string function of JSTL. This function is used to check the input string starts with the given specified character or prefix. It returns true if it contains specified character otherwise returns false.
Syntax of JSTL Function <fn:startsWith()>
boolean:fn:startsWith (java.lang.String, java.lang.String)
Example of JSTL Function <fn:startsWith()>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>JSTL fn:startsWith</title> </head> <body> <p> String "JavaBeat" starts with "J": </p> ${fn:startsWith("JavaBeat",'J')} </body> </html>
Details of the Code
- ${fn:startsWith(“JavaBeat”,’J’)} tag is used to check if the string starts with the given prefix. It returns true if result found correctly otherwise false.
Steps for Execution
- Save this file as startsWith_example.jsp in your eclipse IDE.
- Now select this jsp file, right mouse click and select Run as ->Run on server
Output
When the execution process completed successfully we will get the following output:
Previous Tutorial : JSTL Function fn:split() :: Next Tutorial : JSTL Function fn:substring()