Java Reference
In-Depth Information
anyone editing the HTML around the code. For example, statements to create, open, and
query a database connection, complete with usernames and passwords to gain access to
the data, can be put on a JSP page.
A giant step has been taken with the release of the JSP Standard Tag Library (JSTL), a
set of custom JSP tags and a data-access language that enable JSP-based web applica-
tions to handle presentation without ever resorting to Java code.
Tag libraries, which also are called taglibs , consist of tags that are placed on a JSP page
in a format similar to HTML tags. JSTL's tag library offers functionality common to
most web applications. There are tags for loops and conditionals, tags to read Extensible
Markup Language (XML) documents and database results using Structured Query
Language (SQL), tags for accessing JavaBeans, and support for other tag libraries.
JSTL consists of two complementary components:
A set of five custom JSP tag libraries that provide the core functionality required in
web applications
n
The JSTL Expression Language, which makes it possible to access data at runtime
without using JSP expressions or Java statements
n
There's also a separate version of each JSTL library that works with Java expressions
using existing JSP syntax.
Listing 21.12 contains a demonstration of JSTL and the Expression Language:
hello.jsp , a JSP page that uses a parameter called name as part of a greeting.
LISTING 21.12
The full text of hello.jsp
1: <html>
2: <head>
3: <title>Hello Example</title>
4: </head>
5:
6: <body>
7: <%@ taglib uri='http://java.sun.com/jsp/jstl/core' prefix='c' %>
8:
9: <c:choose>
10: <c:when test='${!empty param.name}'>
11: <h2>Hello, <c:out value='${param.name}'/></h2>
12: </c:when>
13: <c:otherwise>
14: <h2>Hello, stranger</h2>
15: </c:otherwise>
16: </c:choose>
Search WWH ::




Custom Search