Stage 2 · Topic 2 - JSP · Session 5: JSTL Introduction
The slides describe installing JSTL into Tomcat itself:
lib directory.tld files into Tomcat's
WEB-INF directoryweb.xmlC:\Program Files\Apache Tomcat 4.0) and
they modify the server so that every application on it inherits the
library. On a modern container it is wrong for two reasons:
lib folder is loaded into every web application
running on that server, including applications you did not write
and do not trust.JSTL is placed in the application itself:
jsp-demo/
WebContent/
WEB-INF/
lib/
jstl-1.2.jar <-- the whole library, API + implementation + TLDs
and that is the entire installation. Nothing in Tomcat's directories is
touched, and no taglib entries are needed in
web.xml for JSTL, because the container scans every jar in
WEB-INF/lib for .tld files and registers the
libraries it finds automatically.
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> <%@ taglib prefix="x" uri="http://java.sun.com/jsp/jstl/xml" %> <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
http://java.sun.com/... URIs in the slides are
correct and current for JSTL 1.2 — they are just names, not
addresses, and nothing is downloaded from the internet. They only became
jakarta.tags.core etc. in JSTL 2.x, which belongs to the
jakarta.servlet generation of Tomcat (10.1 and later).
javax.servlet.jsp.tagext.TagSupport and the
http://java.sun.com/jsp/jstl/... URIs, because that is what
the slides use and because the installed server is Tomcat 9, which is a
javax container. If you move to Tomcat 10.1 or 11, change
the imports to jakarta.servlet.jsp.* and the taglib URIs to
jakarta.tags.* — nothing else about the syntax of JSP
changes.
JSTL allows a more consistent programming environment by expressing both HTML and procedural code as tags. It does not give you everything a full-featured web application needs, and some things that can be done in JSTL are best not done there.
The perfect example is the database JSTL tags: except for very small web applications, embedding actual database commands into a JSP page is generally considered bad programming practice. The proper location for such code is in Java beans and EJBs used by the application. For routines that occur on many pages, consider creating your own tag library.
In other words: use JSTL for the basic, non-business-specific programming of your pages; put the business logic in beans; and implement the components that are unique to your business in your own tag libraries — which is exactly what Session 3 and Session 7 demonstrate.