The JSTL library is divided into five main groups (also called tag libraries),
each designed for a specific type of functionality.
Tag Group | Purpose | Prefix Example |
---|---|---|
Core Tags | Basic control flow, iteration, variables, URL management | <c:...> |
Formatting Tags | Formatting text, dates, numbers, localization (i18n) | <fmt:...> |
SQL Tags | Executing simple SQL queries (for prototyping) | <sql:...> |
XML Tags | Working with XML data | <x:...> |
Functions Tags | Common functions like string manipulation | ${fn:...} |
🔵 1. Core Tag Library (c
)
- URL:
http://java.sun.com/jsp/jstl/core
- Prefix:
c
- Purpose: Basic common tasks:
- Conditions (
<c:if>
) - Loops (
<c:forEach>
) - Variable management (
<c:set>
,<c:remove>
) - Redirects (
<c:redirect>
) - Imports (
<c:import>
)
- Conditions (
✅ Most commonly used part of JSTL.
🔵 2. Formatting Tag Library (fmt
)
- URL:
http://java.sun.com/jsp/jstl/fmt
- Prefix:
fmt
- Purpose: Formatting and localization (i18n):
- Format numbers, dates, currencies (
<fmt:formatNumber>
,<fmt:formatDate>
) - Set locales
- Access resource bundles (for multilingual sites)
- Format numbers, dates, currencies (
Example:
<fmt:formatDate value="${now}" pattern="dd-MM-yyyy" />
🔵 3. SQL Tag Library (sql
)
- URL:
http://java.sun.com/jsp/jstl/sql
- Prefix:
sql
- Purpose: Basic database access:
- Query databases (
<sql:query>
) - Insert/update/delete (
<sql:update>
) - Manage data sources
- Query databases (
⚠️ Warning: Not recommended for production.
- Only good for prototyping or simple demos.
- In real-world apps, use JDBC, JPA, or ORM frameworks (like Hibernate, Spring Data).
🔵 4. XML Tag Library (x
)
- URL:
http://java.sun.com/jsp/jstl/xml
- Prefix:
x
- Purpose: Working with XML documents:
- Parse XML (
<x:parse>
) - Iterate over XML nodes (
<x:forEach>
) - Output XML values (
<x:out>
)
- Parse XML (
Useful if your app heavily interacts with XML data.
🔵 5. Functions Tag Library (fn
)
- URL:
http://java.sun.com/jsp/jstl/functions
- Prefix:
fn
- Purpose: Provides common functions usable inside EL (
${}
expressions):- String operations (length, contains, split, substring, etc.)
- Collection checks
Example:
${fn:length(userList)}
${fn:toUpperCase(username)}
✅ These functions make EL much more powerful.
🎯 Final Summary Table
Tag Group | Prefix | Purpose |
---|---|---|
Core | c | Conditions, loops, variables |
Formatting | fmt | Numbers, dates, i18n localization |
SQL | sql | Simple database access (only demos) |
XML | x | Parse, navigate XML |
Functions | fn | String/collection functions |
📢 Real-World Tip:
- ✅ In most professional projects, you mainly use Core (
c
), Formatting (fmt
), and Functions (fn
). - ⚠️ SQL (
sql
) and XML (x
) are less common in modern Spring, Hibernate, API-driven applications.