Java.Servlets.Why is it not necessary to configure standard JSP tags in web.xml?

📜 Why Is It NOT necessary to configure standard JSP tags (like JSTL) in web.xml?

✅ Because modern JSP engines (starting from Servlet 2.4 / JSP 2.0 and later)
support automatic tag library discovery based on:

  • URI declarations in the JSP file (using <%@ taglib uri="..." %>)
  • TLD files (.tld) located in standard places inside the JAR files (like /META-INF/)

👉 This means that the container automatically finds and registers standard tag libraries (like JSTL)
without requiring manual mapping in web.xml.

🔥 Technically, what happens:

  1. You write in your JSP:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
  1. The JSP container (e.g., Tomcat) sees the uri.
  2. It automatically searches inside:
    • /WEB-INF/
    • /META-INF/ directories inside all JARs (e.g., jstl.jar, standard.jar)
  3. It finds the corresponding TLD file (Tag Library Descriptor).
  4. It auto-registers the tag library for you.

✅ So you don’t need to declare tag libraries in web.xml anymore.

🛠️ Historically (before JSP 2.0):

  • In older systems (Servlet 2.2 or JSP 1.1/1.2),
    you had to manually map tag libraries in web.xml like this:
<taglib>
    <taglib-uri>/mytags</taglib-uri>
    <taglib-location>/WEB-INF/mytags.tld</taglib-location>
</taglib>

Otherwise, JSP pages wouldn’t know how to find your custom tags.

📢 Modern Reason:

Newer JSP engines follow “declarative programming principles”:

  • Everything needed for a tag library is described inside the TLD and the JAR itself.
  • Deployment becomes easier, cleaner, and less error-prone.
  • You can add JSTL or custom libraries simply by dropping the JARs into /WEB-INF/lib/.

🎯 Final Quick Summary

TopicBefore JSP 2.0JSP 2.0 and later
Need web.xml config✅ Yes, needed❌ No, automatic discovery
How mapping worksManual in web.xmlAuto-discovery from TLD files inside JARs
Standard tagsHarder to useVery easy to use

🚀 Practical Tip for You:

  • When using JSTL (or any other standard tag library),
    ✅ just include the JAR files (jstl.jar, standard.jar),
    ✅ declare the taglib URI in the JSP page,
    ✅ and you’re ready to go — no web.xml config needed!
This entry was posted in Без рубрики. Bookmark the permalink.