JSTL in Action
Shawn Bayern
  • July 2002
  • ISBN 9781930110526
  • 480 pages

JSTL in Action shows you how to write rich, dynamic web pages without programming. From simple loops to tricky XML processing, every feature of JSTL is covered and exercised in numerous useful examples. Whether you are a novice page author or an experienced Java programmer, this book shows you easy ways to create powerful web sites.

About the Technology

JSTL is an important simplification of the Java web platform. With JSTL, page authors can now write dynamic pages using standard HTML-like tags and an easy-to-learn expression language. JSTL is a standard from the Java Community Process, and its expression language will become part of JSP 2.0.

About the book

To help readers who don't already have a JSP container run the examples in the book, there's a free companion download here. This bundle contains a ready-to-run JSP container, a JSTL implementation, and all the book's examples.

Table of Contents detailed table of contents



about this book

about the cover illustration

Part 1 Background

1. Dynamic web sites

1.1. The boring life of a web browser

1.2. The simple ideas behind dynamic web content

1.3. What you need to run JSTL

1.3.1. JSP containers

1.4. Real-world web applications

1.5. Summary

2. Foundation: XML and JSP

2.1. Introduction to XML

2.1.1. A dose of tag terminology

2.1.2. The relevant rules of XML

2.2. Introduction to JSP

2.2.1. JSP tag syntax

2.2.2. Standard JSP tags

2.2.3. JSP tag libraries

2.2.4. Other JSP directives

2.2.5. JSP comments

2.2.6. How JSP organizes data

2.3. Summary

Part 2 Learning JSTL

3. The expression language

3.1. Expressions and the <c:out> tag

3.1.1. What expressions look like

3.1.2. Where expressions work

3.1.3. Default values in <c:out>

3.1.4. Special characters and <c:out>

3.2. Scoped variables and the expression language

3.2.1. Basic syntax to access scoped variables

3.2.2. Different types of scoped data

3.3. Request parameters and the expression language

3.3.1. HTML forms

3.3.2. A page that reads request parameters

3.4. More powerful expressions

3.4.1. Different ways to access properties

3.4.2. Accessing other data with the expression language

3.4.3. Comparisons

3.4.4. Boolean operations and parentheses

3.4.5. Multiple expressions

3.5. Saving data with <c:set>

3.6. Deleting data with <c:remove>

3.7. Summary

4. Controlling flow with conditions

4.1. Different kinds of decisions

4.2. Yes-or-no conditions with <c:if>

4.2.1. The basic syntax of <c:if>

4.2.2. Using <c:if> within HTML tags

4.2.3. Multiple <c:if> tags

4.2.4. Nested <c:if> tags

4.2.5. The var and scope attributes

4.3. Mutually exclusive conditions with <c:choose>, <c:when>, and <c:otherwise>

4.3.1. Why JSTL has complex conditional tags

4.3.2. How the complex con-ditional tags work

4.3.3. Rules for using the complex conditional tags

4.4. Summary

5. Controlling flow with loops

5.1. General-purpose looping with <c:forEach>

5.2. Iterating over strings with <c:forTokens>

5.2.1. How JSTL parses strings

5.3. Advanced iteration with <c:forEach> and <c:forTokens>

5.3.1. Looping over part of a collection

5.3.2. Looping over numbers

5.3.3. Loop status

5.4. Loop example: scrolling through results

5.4.1. Understanding the example

5.4.2. Using varStatus in the example

5.5. Summary

6. Importing text

6.1. Including text with the <c:import> tag

6.1.1. Absolute and relative URLs

6.1.2. Retrieving data from URLs

6.1.3. Saving information for later

6.1.4. Communicating with imported pages

6.1.5. Import example: a customized header

6.2. Redirecting with <c:redirect>

6.3. Formatting URLs with <c:url>

6.3.1. How to use <c:url>

6.3.2. Why to use <c:url>

6.4. Summary

7. Selecting XML fragments

7.1. XPath’s vision of an XML document

7.2. XPath’s basic syntax

7.2.1. Deep descendants

7.2.2. Attributes

7.2.3. Predicates and element order

7.2.4. Strings and booleans

7.3. XPath variables and JSTL

7.4. JSTL, XPath, and namespaces

7.5. More advanced XPath

7.5.1. Nodes and axes

7.5.2. Contexts

7.5.3. Further reading

7.6. Summary

8. Working with XML fragments

8.1. Parsing documents with <x:parse>

8.1.1. Sources of XML

8.2. Accessing XML with <x:out> and <x:set>

8.2.1. Finding a document

8.2.2. The <x:out> tag

8.2.3. The <x:set> tag

8.3. Control flow based on XML documents

8.3.1. Simple conditions with <x:if>

8.3.2. Compound conditions with <x:choose>

8.3.3. Looping over parts of a document with <x:forEach>

8.4. XML transformations using JSTL

8.4.1. Simple transformations with <x:transform>

8.4.2. Using the var attribute

8.4.3. XSLT parameters

8.4.4. Advantages of using XSLT within JSTL

8.5. An XML example: reading RSS files

8.6. Summary

9. Database-driven pages

9.1. When to use JSTL’s database support

9.1.1. When to use databases

9.1.2. Direct access from JSP pages

9.2. Setting up a database connection with <sql:setDataSource>

9.2.1. Caution against <sql:setDataSource>

9.3. Performing queries with <sql:query>

9.3.1. Performing a database query

9.3.2. Reading a query’s results

9.3.3. Limiting the size of a query’s result

9.4. Modifying data with <sql:update>

9.4.1. Simple uses of the <sql:update> tag

9.4.2. Measuring the effect of an <sql:update> tag

9.5. Using <sql:param> with adjustable queries

9.5.1. Template queries

9.5.2. Safe, convenient parameters with <sql:param>

9.5.3. Date parameters with <sql:dateParam>

9.6. Managing transactions with <sql:transaction>

9.6.1. The <sql:transaction> tag

9.6.2. Transaction isolation

9.7. SQL example: a hit counter

9.8. Summary

10. Formatting and internationalization

10.1. Printing numbers with <fmt:formatNumber>

10.1.1. Basic usage of <fmt:formatNumber>

10.1.2. Different ways to specify a value

10.1.3. Storing a number instead of printing it

10.1.4. Printing different types of numbers: percentages and currencies

10.1.5. Grouping digits together — or not

10.1.6. Controlling how many digits print

10.1.7. More control: custom number patterns

10.2. Printing dates with <fmt:formatDate>

10.2.1. Differences from <fmt:formatNumber>

10.2.2. Printing times, dates, or both

10.2.3. Printing longer or shorter dates and times

10.2.4. More control: custom date patterns

10.3. Reading numbers with <fmt:parseNumber>

10.3.1. Why you might want to parse numbers

10.3.2. How <fmt:parseNumber> works by default

10.3.3. Changing <fmt:parseNumber>'s parsing rules

10.4. Reading dates with <fmt:parseDate>

10.4.1. How <fmt:parseDate> parses dates by default

10.4.2. Changing how <fmt:parseDate> parses dates

10.5. Overriding time zones with <fmt:timeZone> and <fmt:setTimeZone>

10.5.1. How JSTL figures out time zones by default

10.5.2. Setting time zones for individual tags

10.5.3. Long-lasting changes with <fmt:setTimeZone>

10.5.4. Temporary changes with <fmt:timeZone>

10.6. Overriding locales with <fmt:setLocale>

10.6.1. How to identify locales

10.6.2. The parseLocale attribute for <fmt:parseNumber> and <fmt:parseDate>

10.7. Internationalizing text messages with <fmt:message>, <fmt:param>, <fmt:bundle>, and <fmt:setBundle>

10.7.1. Using <fmt:message>

10.7.2. Loading a bundle family with <fmt:bundle> and <fmt:setBundle>

10.8. Summary

Part 3 JSTL in action

11. Common tasks

11.1. Handling checkbox parameters

11.1.1. The HTML form

11.1.2. A simple checkbox handler

11.1.3. Handling some check boxes specially

11.2. Accepting dates

11.2.1. The HTML form

11.2.2. Handling the form and reading the date

11.3. Handling errors

11.3.1. Ignoring the issue

11.3.2. Catching errors with <c:catch>

11.3.3. Passing errors to an error page

11.4. Validating input

11.4.1. Different kinds of form validation

11.4.2. Tasks involved when validating a form

11.4.3. A sample form validation

11.5. Summary

12. Dynamic features for web sites

12.1. An online survey

12.1.1. What our survey looks like

12.1.2. Setting up the survey database

12.1.3. Adding survey questions to pages

12.1.4. How the survey works

12.2. A message board

12.2.1. What our message board looks like

12.2.2. Setting up the message database

12.2.3. Linking to appropriate message boards

12.2.4. How the message board works

12.3. Summary

13. Case study in building a web site

13.1. Managing the layout

13.1.1. A framework for channels

13.1.2. Modular channels

13.2. Adding dynamic content

13.2.1. Including RSS channels

13.2.2. Including other dynamic content

13.3. Registering users

13.3.1. Modifying the header

13.3.2. The registration form

13.3.3. Saving the registration

13.3.4. The user database

13.4. Authenticating users

13.4.1. Logging in users

13.4.2. Some notes about authentication

13.5. Personalizing the site

13.5.1. Filling in a form automatically

13.5.2. Displaying a chosen RSS feed

13.6. Summary

Part 4 JSTL for programmers

14. Control and performance

14.1. Scripting elements and the JSTL rtexprvalue libraries

14.1.1. Warning against scripting expressions

14.1.2. JSTL’s dual libraries

14.1.3. Scripting variables and <jsp:useBean>

14.2. Modifying properties with <c:set>

14.3. Advanced techniques for importing text

14.3.1. Representing imported text as a java.io.Reader

14.3.2. Character encoding

14.4. Advanced XML parsing and manipulation

14.4.1. XML data formats

14.4.2. Telling <x:parse> where a document came from

14.4.3. Efficient parsing with org.xml.sax.XMLFilter

14.4.4. Efficient transformations with javax.xml.transform.Result

14.5. Deciphering requests with <fmt:requestEncoding>

14.6. Exposing data to JSP pages

14.6.1. Saving data to a scope

14.6.2. Exposing dynamic data structures

14.6.3. Writing JavaBeans

14.7. Configuring JSTL

14.7.1. Providing default information to JSTL tags

14.7.2. Managing database access

14.7.3. Managing internationalization

14.8. Enforcing good page-authoring habits

14.8.1. Requiring script-free pages

14.9. Summary

15. Using JSTL to develop custom tags

15.1. Developing and installing tag libraries

15.1.1. JSTL’s support for tag-handler developers

15.1.2. The tag-library descriptor (TLD)

15.1.3. Installing and using a tag library

15.2. Developing conditional tags

15.2.1. A simple conditional tag

15.2.2. A conditional tag with attributes

15.2.3. Integrating custom conditional tags with standard tags

15.2.4. Using the expression language

15.3. Developing iteration tags

15.3.1. A simple loop tag

15.3.2. More advanced iteration tags

15.4. Summary

Appendix A: JSTL reference

A.1. Expression language syntax

A.2. Core tag library

A.3. XML tag library

A.4. Database tag library

A.5. Formatting tag library

Appendix B: JSTL API (for developers)

B.1. Configuration variables

B.2. Conditions and loops

B.3. Interoperating with JSTL’s database tags

B.4. Using JSTL’s localization algorithms

Appendix C: Database tags and SQL

C.1. SQL and <sql:update>

C.2. SQL and <sql:query>

C.3. SQL miscellany

C.4. Summary

Appendix D: References and resources

D.1. JSP Standard Tag Library

D.3. Databases

D.5. Miscellaneous references


What's inside

  • Mixing HTML tags and JSTL
  • JSTL's expression language
  • Working with loops and conditions
  • Painless XML processing
  • Accessing databases
  • Text formatting
  • Internationalization
  • JSTL configuration and performance
  • Many examples including
    • How to register and authenticate users
    • Running an online survey
    • How to build a discussion forum
    • Designing a web portal

About the author

Shawn Bayern is a research programmer at Yale University and coauthor of Manning's Web Development with Java Server Pages. He is the reference implementation lead for JSTL.

placing your order...

Don't refresh or navigate away from the page.
print book $29.96 $39.95 pBook + PDF
Additional shipping charges may apply
JSTL in Action (print book) added to cart
continue shopping
go to cart

eBook $23.99 $31.99 PDF only
JSTL in Action (eBook) added to cart
continue shopping
go to cart

Prices displayed in rupees will be charged in USD when you check out.
customers also reading

This book 1-hop 2-hops 3-hops

FREE domestic shipping on three or more pBooks