Datasheet

Patrick c01.tex V3 - 09/18/2009 12:15pm Page 16
Chapter 1: Building Web Applications in WebLogic
Calling Custom Tags in JSP Pages
Custom tags are invoked within JSP pages by embedding the appropriate XML tags in your page using
the syntax
<prefix:tagname attribute1="value1"
...
attributeN="valueN" />
or
<prefix:tagname attribute1="value1"
...
attributeN="valueN" >
...
</prefix:tagname>
The prefix represents the short name you gave a particular library when it was declared in your page, the
tagname is the specific tag or function identifier within the library, and the attribute/value pairs are the
data or settings needed by the tag for proper operation.
For example, if you’ve declared the JSTL
core
library using a prefix
c
with a
taglib
directive
like this:
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
you would invoke the
out
tag within the JSTL core library to display the contents of the request parame-
ter
employeeNum
using the following syntax:
<c:out value="${requestScope.employeeNum}"/>
The equivalent scriptlet code, for comparison purposes, might look like this:
<%= request.getParameter("employeeNum") %>
Although this JSTL example does not appear to be significantly shorter or simpler than using
scriptlet code in this trivial example, the difference becomes much larger with more complex
operations.
Using Expression Language in JSTL Calls
The JSTL libraries support the use of Expression Language (EL) within many of the attribute/value pairs
supplied to the custom tags. To understand the difference between an invocation with and without EL
support, consider the following two calls to the
out
tag in the
core
JSTL library:
<c:out value="requestScope.employeeNum" />
<c:out value="${requestScope.employeeNum}" />
The first call passes a simple string to the tag implementation via the
value
attribute. This string is
simply placed in the output response being generated by the JSP, and the users would see the string
requestScope.employeeNum
on their web page.
The second call informs the custom tag implementation that it is using the EL syntax by including
$
{ ... } characters within the
value
attribute passed to the tag. The tag sees this syntax and treats the
16