Java.Servlet.What tag groups does the JSTL library consist of?

The JSTL library is divided into five main groups (also called tag libraries),
each designed for a specific type of functionality.

Tag GroupPurposePrefix Example
Core TagsBasic control flow, iteration, variables, URL management<c:...>
Formatting TagsFormatting text, dates, numbers, localization (i18n)<fmt:...>
SQL TagsExecuting simple SQL queries (for prototyping)<sql:...>
XML TagsWorking with XML data<x:...>
Functions TagsCommon 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>)

✅ 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)

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

⚠️ 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>)

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 GroupPrefixPurpose
CorecConditions, loops, variables
FormattingfmtNumbers, dates, i18n localization
SQLsqlSimple database access (only demos)
XMLxParse, navigate XML
FunctionsfnString/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.
This entry was posted in Без рубрики. Bookmark the permalink.