🧩 AJP Lab Exercise-14 — JSTL Function Tag Demonstration

Demonstrates JSTL fn functions for string operations and list processing inside JSP.

🧰 Prerequisites

  • Apache Tomcat 9 (javax) or Tomcat 10+ (Jakarta)
  • JDK properly installed
  • JSTL JARs placed in WEB-INF/lib

⚙️ Steps to Execute

0) Folder structure

C:\AJP_LAB14_JSTL_FUNCTION\
 └── FunctionDemoApp\
     ├── functiontag.jsp
     └── WEB-INF\
         ├── web.xml
         └── lib\
             ├── jakarta.servlet.jsp.jstl-3.0.1.jar
             └── jakarta.servlet.jsp.jstl-api-3.0.1.jar

1) JSP Code (functiontag.jsp)

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<html>
<head>
    <title>JSTL Function Tag Example</title>
</head>
<body>
    <h2>JSTL Function Tag Demonstration</h2>

    <c:set var="message" value="Hello JSTL Functions Example" />
    <c:set var="fruits" value="Apple,Banana,Mango,Orange" />

    <p><b>Original Message:</b> ${message}</p>
    <p><b>Uppercase:</b> ${fn:toUpperCase(message)}</p>
    <p><b>Lowercase:</b> ${fn:toLowerCase(message)}</p>
    <p><b>Substring (0-5):</b> ${fn:substring(message,0,5)}</p>
    <p><b>Length of Message:</b> ${fn:length(message)}</p>
    <p><b>Contains 'JSTL'?</b> ${fn:contains(message, 'JSTL')}</p>
    <p><b>Starts With 'Hello'?</b> ${fn:startsWith(message, 'Hello')}</p>
    <p><b>Ends With 'Test'?</b> ${fn:endsWith(message, 'Test')}</p>

    <h3>Working with Collections</h3>
    <p><b>Fruits List (String):</b> ${fruits}</p>

    <c:set var="fruitList" value="${fn:split(fruits, ',')}" />
    <p><b>Number of Fruits:</b> ${fn:length(fruitList)}</p>
    <p><b>First Fruit:</b> ${fruitList[0]}</p>
</body>
</html>

2) web.xml (Deployment Descriptor)

<web-app xmlns="http://java.sun.com/xml/ns/javaee" version="3.0">
  <welcome-file-list>
    <welcome-file>functiontag.jsp</welcome-file>
  </welcome-file-list>
</web-app>

3) Place Required JARs

  • jakarta.servlet.jsp.jstl-3.0.1.jar
  • jakarta.servlet.jsp.jstl-api-3.0.1.jar

These JARs go inside your project’s WEB-INF/lib folder.

4) Deploy and Run

copy /E C:\AJP_LAB14_JSTL_FUNCTION\FunctionDemoApp C:\apache-tomcat-10.1\webapps\

Then open in browser:

http://localhost:8080/FunctionDemoApp/

5) Expected Output

JSTL Function Tag Demonstration

Original Message: Hello JSTL Functions Example
Uppercase: HELLO JSTL FUNCTIONS EXAMPLE
Lowercase: hello jstl functions example
Substring (0-5): Hello
Length of Message: 28
Contains 'JSTL'?: true
Starts With 'Hello'?: true
Ends With 'Test'?: false

Fruits List (String): Apple,Banana,Mango,Orange
Number of Fruits: 4
First Fruit: Apple

✅ If you see this — JSTL function tags are working perfectly.

📦 Download JSTL JAR Files

📥 Download jakarta.servlet.jsp.jstl-api-3.0.1.jar    📥 Download jakarta.servlet.jsp.jstl-3.0.1.jar

⚠️ Troubleshooting

  • fn: tag not found: JSTL JARs missing or placed outside WEB-INF/lib.
  • Cannot resolve functions: Taglib URI mismatch — keep it as http://java.sun.com/jsp/jstl/functions.
  • ClassNotFoundException: Version mismatch (use 3.0.1 for Jakarta Tomcat 10+).