You are previewing JavaServer Pages™, Second Edition.
O'Reilly logo
JavaServer Pages™, Second Edition

Book Description

Since being introduced in 1999, JavaServer Pages™ (JSP) have become a popular and important technology for building dynamic, interactive, content-rich Web sites. JavaServer Pages™, Second Edition is a hands-on guide to working with JSP, offering the easiest and most efficient ways for non-programmers and Web designers to create sophisticated, dynamic sites. Programmers can also utilize this book to independently create new dynamic components. This second edition covers the latest release of the JSP specification (2.0), many standard extensions to JSPs, and a number of best practices that have been developed since the publication of the first edition.

This book also offers overviews of some related technologies, including:

  • JavaBeans™

  • Servlets

  • JavaServer Pages Standard Tag Library (JSTL)

  • Jakarta Struts

  • Databases

  • JavaServer Pages™, Second Edition contains all the information necessary to start writing JSP--for anyone who has a computer and can write HTML. It includes practical, Java-based techniques for maintaining and personalizing information-rich Web sites, as well as examples based on Jakarta Struts, the new JSP toolkit. Recent updates provide a number of new tools and techniques that will allow readers to get the most productivity from JSPs, with the least amount of effort.

    Also included is a CD-ROM containing everything you need to get started. The tools, which are free, open-source, stable, secure, and run on pretty much every platform, are powerful enough to serve even a mid-sized Web site without problems. Contents of the CD-ROM include: Tomcat™, the open-source reference implementation of the latest JSP and Servlet specification; useful libraries such as the JavaServer Pages Standard Tag Library (JSTL) and Struts; Hsqldb, a self-contained, 100 percent pure Java database; all the code examples from the book; and a number of Java beans, providing ready-to-use components for many of the tasks frequently needed on a dynamic Web page.



    0321150791B06042003

    Table of Contents

    1. Copyright
      1. Dedication
    2. Preface
    3. Acknowledgements
    4. 1. Introduction
      1. 1.1. A Brief History of the Web
      2. 1.2. Basic Dynamic Page Generation
      3. 1.3. Solving CGI Problems
        1. 1.3.1. Speeding up CGI
        2. 1.3.2. Separating HTML from Code
        3. 1.3.3. Servlets and JavaServer Pages
      4. 1.4. Welcome to Java News Today
      5. 1.5. Trying the Examples
    5. 2. Simple JSPs
      1. 2.1. Removing Text from a JSP
      2. 2.2. JSP Errors
      3. 2.3. Including Text in a JSP
      4. 2.4. The Phases of a JSP
      5. 2.5. Creating Custom Error Pages
      6. 2.6. Java News Today
      7. 2.7. Summary and Conclusions
      8. 2.8. Tags Learned in This Chapter
    6. 3. Using Beans
      1. 3.1. Splitting Big Tasks into Manageable Pieces
      2. 3.2. Defining Beans
      3. 3.3. JavaBean Tags
        1. 3.3.1. Getting a Property
        2. 3.3.2. Setting Properties
          1. The Connection Between Forms and Properties
          2. Form Values
      4. 3.4. Making Data Available Throughout an Application
        1. 3.4.1. The Page Scope
        2. 3.4.2. The Request Scope
        3. 3.4.3. The Session Scope
        4. 3.4.4. The Application Scope
      5. 3.5. Special Actions When Beans Are Created
      6. 3.6. Making Beans Last Forever
      7. 3.7. Java News Today and Beans
      8. 3.8. Future Directions
      9. 3.9. Summary and Conclusions
      10. 3.10. Tags Learned in This Chapter
    7. 4. The Standard Tag Library
      1. 4.1. Tag Libraries
      2. 4.2. Tags with Bodies
      3. 4.3. Dynamic Attributes in Tags
      4. 4.4. Displaying Expressions
      5. 4.5. Formatting Output
      6. 4.6. Compound Data in the Expression Language
        1. 4.6.1. Repeating a Section of a Page
        2. 4.6.2. Optionally Including Sections of a Page
      7. 4.7. Browser Detection
      8. 4.8. Combining Tags
      9. 4.9. Selecting among Multiple Choices
      10. 4.10. Summary and Conclusions
      11. 4.11. Tags Learned in this Chapter
    8. 5. Java News Today: Part I
      1. 5.1. The Beans
      2. 5.2. The Header
      3. 5.3. The Left-Hand Navigation
      4. 5.4. The Login Page
      5. 5.5. The Quiz Result Page
      6. 5.6. The Section Page
      7. 5.7. The Article Page
      8. 5.8. The Remaining Pages
      9. 5.9. Summary and Conclusions
      10. 5.10. Tags Learned in this Chapter
    9. 6. Databases
      1. 6.1. A Quick Introduction to Databases
      2. 6.2. A Language for Databases
      3. 6.3. Using SQL Directly from JSPs
      4. 6.4. Inserting Data from JSPs
      5. 6.5. SQL and Beans
      6. 6.6. Summary and Conclusions
      7. 6.7. Tags Learned in This Chapter
    10. 7. Java News Today: Part 2
      1. 7.1. Designing the Tables
      2. 7.2. Adding Articles
      3. 7.3. User Pages
      4. 7.4. Other User Preferences
      5. 7.5. Advertising
      6. 7.6. Summary and Conclusions
    11. 8. Working with XML
      1. 8.1. A Brief Introduction to XML
      2. 8.2. Using XML in JSPs
      3. 8.3. Selecting Data from an XML Document
      4. 8.4. Processing XML in JSPs
      5. 8.5. Formatting XML
      6. 8.6. Java News Today and XML
      7. 8.7. Summary and Conclusions
      8. 8.8. Tags Learned in this Chapter
    12. 9. A Small Cup of Java
      1. 9.1. Expressions
      2. 9.2. Types
      3. 9.3. Storing Values
      4. 9.4. Method Calls
      5. 9.5. Conditionally Evaluating Code
      6. 9.6. Evaluating the Same Code Multiple Times
      7. 9.7. Grouping Code
      8. 9.8. Handling Errors
      9. 9.9. Modeling a Problem with Objects
      10. 9.10. Objects in Java
      11. 9.11. Building Objects from Classes
      12. 9.12. Sometimes Nothing Is Something
      13. 9.13. Building Classes from Other Classes
      14. 9.14. Interfaces
      15. 9.15. Creating Groups of Classes and Interfaces
      16. 9.16. Using Java in JSPs
      17. 9.17. Database Access from Java
      18. 9.18. Summary and Conclusions
    13. 10. Writing Beans
      1. 10.1. How Beans Are Implemented
      2. 10.2. Automatic Type Conversion
      3. 10.3. How Beans Work
      4. 10.4. Bean Serialization
      5. 10.5. Events
      6. 10.6. Special Events
      7. 10.7. Bean Errors
      8. 10.8. Summary and Conclusions
    14. 11. Servlets
      1. 11.1. The Servlet Life Cycle
      2. 11.2. The Servlet Class Hierarchy
        1. 11.2.1. More about Requests
        2. 11.2.2. More about Responses
        3. 11.2.3. Convenience Methods
      3. 11.3. Servlet Events
      4. 11.4. Forwarding and Including Requests
      5. 11.5. Using Scopes from Servlets
      6. 11.6. Using Beans from Servlets
      7. 11.7. The JSP Classes
      8. 11.8. Intercepting Requests
      9. 11.9. Summary and Conclusions
    15. 12. The Controller
      1. 12.1. Some Common Controller Tasks
      2. 12.2. Support for Controllers: Struts
        1. 12.2.1. Using Struts
        2. 12.2.2. Providing Security
        3. 12.2.3. Struts and JNT
      3. 12.3. Summary and Conclusions
    16. 13. Creating New Tag Libraries
      1. 13.1. The Tag Life Cycle
      2. 13.2. Tags without Bodies
      3. 13.3. Tags with Bodies
      4. 13.4. Using the Expression Language
      5. 13.5. JSPs as Custom Tags
      6. 13.6. Summary and Conclusions
    17. 14. Advanced Topics
      1. 14.1. Declaring Variables and Methods
      2. 14.2. Extending Different Classes
      3. 14.3. Returning Other Kinds of Data
      4. 14.4. Threads
        1. 14.4.1. Avoiding Thread Problems
        2. 14.4.2. Using Threads
      5. 14.5. Advanced Error Handling
      6. 14.6. Summary and Conclusions
    18. A. Summary of Tags
      1. A.1. Built-in Tags
      2. A.2. Core Tags
      3. A.3. Format, Parsing, and Internationalization Tags
      4. A.4. SQL Tags
      5. A.5. XML Tags
    19. B. Configuring a Web Application
      1. B.1. Layout of the Directories
      2. B.2. The Web.xml File