










Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An overview of jstl (javaserver pages standard tag library), its functional areas, and various tag libraries including core, xml, internationalization, database access, and functions. It also includes examples and declarations of jstl tag libraries.
Typology: Slides
1 / 18
This page cannot be seen from the preview
Don't miss anything!











Lecture 12 - JSTL (JSP Standard Tag Library) Reference: JAVA EE 5 TUTORIAL
What is and Why JSTL? JSTL Functional areas Core tags Database Access tags XML tags Quick review on XPath Internationalization and Text Formatting tags EL (Expression Language) functions tags
Standard set of tag libraries Encapsulates core functionality common to many JSP applications iteration and conditionals XML database access internationalized formatting Likely to evolve to add more commonly used tags in future versions
You don't have to write them yourself You learn and use a single standard set of tag libraries that are already provided by compliant Java EE platforms Vendors are likely to provide more optimized implementation Portability of your applications are enabled
Declaration of JSTL Tag Libraries Core <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> XML <%@ taglib prefix="x" uri="http://java.sun.com/jsp/jstl/xml" %> Internationalization (i 18 n) <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> Database (SQL) <%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql" %> Functions <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
URL management <c:import> <c:param> <c:redirect> <c:param> <c:url> <c:param> General purpose <c:out> <c:catch>
Sets the value of an EL variable or the property of an EL variable via “var” attribute in any of the JSP scopes via “scope” attribute page, request, session, application If the variable does not already exist, it gets created and saved (in the scope object) Variable can be set in 2 different ways <c:set var="foo" scope="session" value="..."/> example: <c:set var="bookId" value="${param.BookID}"/> <c:set var="foo">value to be set</c:set>
<h 4 >Using "customerTable" application scope attribute defined in Set.jsp a first time</h 4 > <c:out value="${customerTable}" escapeXml="false"/> <h 4 >Using "customerTable" application scope attribute defined in Set.jsp a second time</h 4 > <c:out value="${customerTable}" escapeXml="false" />
Flow control tags eliminate the need for scriptlets Without conditional tags, a page author must generally resort to using scriptlets in JSP page <c:if test=”..”> Conditional execution of its body according to value of a test attribute <c:choose> Performs conditional block execution by the embedded <c:when> and <c:otherwise> sub tags Works like if-then-else
Example: <c:if test=”...”>, ./conditionals/If.jsp <c:forEach var="customer" items="${customers}"> <c:if test="${customer.address.country == 'USA'}"> ${customer}
</c:if> </c:forEach> Only the customers whose “address.country” property value is “USA” are displayed through <c:forEach> loop.