();
books.add("The Pragmatic Programmer");
books.add("Clean Code");
books.add("Design Patterns");
books.add("Effective Java");
books.add("Java: The Complete Reference");
return books;
}
%>
<%
// Set up sample data for taglib demonstration
request.setAttribute("bookList", getSampleBooks());
request.setAttribute("currentDate", new Date());
request.setAttribute("userCount", 42);
request.setAttribute("serverName", "Gumdrop");
%>
Taglib Example - Gumdrop JSP
Taglib Example
← Back to JSP Examples
Note: This JSP demonstrates taglib directive processing and custom tag recognition
by Gumdrop's JSP implementation. To fully execute JSTL tags, you would need to add the
JSTL JAR files to your WEB-INF/lib directory.
This JSP demonstrates:
Taglib directive processing
Custom tag recognition and code generation
Tag Library Descriptor (TLD) resolution
Interaction with Gumdrop's TaglibRegistry
Taglib Directives
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
These directives register tag library prefixes that Gumdrop's JSP implementation
will recognize and process during code generation.
JSTL Core Tags (Demonstration)
Conditional Logic
<c:if test="\${not empty serverName}">
<p>Server: <c:out value="\${serverName}"/></p>
</c:if>
Generated Output (if JSTL were available):
Server: <%= request.getAttribute("serverName") %>
Iteration
<c:forEach var="book" items="\${bookList}" varStatus="status">
<p>\${status.index + 1}. <c:out value="\${book}"/></p>
</c:forEach>
Generated Output (if JSTL were available):
<%
java.util.List
books = (java.util.List) request.getAttribute("bookList");
for (int i = 0; i < books.size(); i++) {
String book = books.get(i);
%>
<%= (i + 1) %>. <%= book %>
<%
}
%>
Variable Setting and Output
<c:set var="welcomeMsg" value="Welcome to \${serverName} JSP Engine"/>
<p><c:out value="\${welcomeMsg}"/></p>
Generated Output (if JSTL were available):
Welcome to <%= request.getAttribute("serverName") %> JSP Engine
Formatting Tags
<fmt:formatDate value="\${currentDate}" pattern="yyyy-MM-dd HH:mm:ss"/>
<fmt:formatNumber value="\${userCount}" type="number"/>
Generated Output (if JSTL were available):
<%
Date currentDate = (Date) request.getAttribute("currentDate");
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
%>
Formatted Date: <%= sdf.format(currentDate) %>
Formatted Number: <%= request.getAttribute("userCount") %>
How Gumdrop Processes Taglibs
Taglib Directive Processing: When parsing, Gumdrop extracts
taglib directives and registers prefix-to-URI mappings in the JSPPage.
TLD Resolution: The TaglibRegistry resolves taglib URIs to
Tag Library Descriptor (TLD) files in WEB-INF/lib JARs or WEB-INF/ directory.
Custom Tag Recognition: During parsing, custom tags
(like <c:if>) are recognized based on registered prefixes.
Code Generation: The JSPCodeGenerator creates Java code
that instantiates tag handler classes and calls their lifecycle methods.
Tag Handler Integration: Generated servlet code properly
initializes PageContext and manages tag handler lifecycle
(doStartTag, doEndTag, release).
To Enable Full JSTL Support
To make these tags fully functional, you would need to:
Download JSTL JAR files (jstl-1.2.jar, standard-1.1.2.jar)
Place them in your WEB-INF/lib/ directory
Restart Gumdrop to reload the web application
Gumdrop's JSP implementation would then:
Find the TLD files inside the JSTL JARs
Generate appropriate Java code for tag instantiation
Handle tag attributes and body content
Manage tag handler lifecycle properly
Taglib Architecture
Gumdrop's taglib support includes:
TaglibRegistry: Manages taglib URI-to-TLD mappings
TldParser: SAX-based parser for Tag Library Descriptors
TagLibraryDescriptor: In-memory representation of TLD metadata
Custom Tag Code Generation: Generates proper tag handler instantiation and lifecycle management
Gumdrop JSP Engine - Full JSP 2.0+ Taglib Support