Download
FAQ
History
PrevHomeNext API
Search
Feedback
Divider

JavaServer Pages Standard Tag Library

The JavaServer Pages Standard Tag Library (page 689) (JSTL) encapsulates core functionality common to many JSP applications. Instead of iterating over lists using a scriptlet or different iteration tags from numerous vendors, JSTL defines a standard set of tags. This standardization allows you to learn a single set of tags and use them on multiple JSP containers. Also, a standard tag library is more likely to have an optimized implementation.

JSTL consists of several sub libraries that handle the follow functions:

Here's the JSP page from the previous section rewritten to use the JSTL fn:length function and c:if tag to perform the checks done by the scriptlet:

// greeting.jsp 
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" 
  prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions"
  prefix="fn" %>
<html>
<head><title>Hello</title></head>
<body bgcolor="white">
<img src="duke.waving.gif"> 
<h2>Hello, my name is Duke. What's yours?</h2>
<form method="get">
<input type="text" name="username" size="25">
<p></p>
<input type="submit" value="Submit">
<input type="reset" value="Reset">
</form>

<jsp:useBean id="userNameBean" class="hello.UserNameBean" 
  scope="request"/>
<jsp:setProperty name="userNameBean" property="name" 
  value="${param.username}" />

<c:if test="${fn:length(userNameBean.name) > 0}" >
  <%@include file="response.jsp" %>
</c:if>

</body>
</html> 

JSTL contains many useful functions and it is hard to see limitations in this small example. Indeed, JSTL excels when prototyping small Web applications. Its limitations become more evident in Web applications containing several UI input components on a given page whose input must be validated or in Web applications with many pages. Thus, what's missing from JSTL are the larger granularity functions, such as user interface components and mechanisms for controlling the flow from one page to the next.

Divider
Download
FAQ
History
PrevHomeNext API
Search
Feedback
Divider

All of the material in The Java(TM) Web Services Tutorial is copyright-protected and may not be published in other works without express written permission from Sun Microsystems.