Cover image for JavaServer Pages, Second Edition

Table of Contents

  1. JavaServer Pages, 2nd Edition
    1. Preface
      1. What’s in the Book
      2. Readers of the First Edition
      3. Audience
        1. What You Need to Know
      4. Organization
        1. Part I
        2. Part II
        3. Part III
        4. Part IV
      5. About the Examples
      6. Conventions Used in This Book
      7. How to Contact Us
      8. Acknowledgments for First Edition
      9. Acknowledgments for Second Edition
    2. I. JSP Application Basics
      1. 1. Introducing JavaServer Pages
        1. What Is JavaServer Pages?
        2. Why Use JSP?
          1. Embedding Dynamic Elements in HTML Pages
          2. Compilation
          3. Using the Right Person for Each Task
          4. Integration with Enterprise Java APIs
          5. Other Solutions
            1. Active Server Pages (ASP)
            2. PHP
            3. ColdFusion
            4. Java servlet template engines
          6. The JSP Advantage
        3. What You Need to Get Started
      2. 2. HTTP and Servlet Basics
        1. The HTTP Request/Response Model
          1. Requests in Detail
          2. Responses in Detail
          3. Request Parameters
          4. Request Methods
        2. Servlets
          1. Advantages over Other Server-Side Technologies
          2. Servlet Containers
          3. Servlet Contexts and Web Applications
      3. 3. JSP Overview
        1. The Problem with Servlets
        2. The Anatomy of a JSP Page
        3. JSP Processing
          1. JSP Elements
            1. Directive elements
            2. Standard action elements
            3. Custom action elements and the JSP Standard Tag Library
            4. Scripting elements
            5. JavaBeans components
        4. JSP Application Design with MVC
      4. 4. Setting Up the JSP Environment
        1. Installing the Java Software Development Kit
        2. Installing the Tomcat Server
          1. Windows Platforms
          2. Unix Platforms (Including Linux and Mac OS X)
        3. Testing Tomcat
        4. Installing the Book Examples
        5. Example Web Application Overview
    3. II. JSP Application Development
      1. 5. Generating Dynamic Content
        1. Creating a JSP Page
        2. Installing a JSP Page
        3. Running a JSP Page
        4. Using JSP Directive Elements
          1. JSP Comments
        5. Using Template Text
        6. Using JSP Action Elements
          1. JSP Standard Tag Library
            1. The JSTL Expression Language
      2. 6. Using JavaBeans Components in JSP Pages
        1. What Is a Bean?
        2. Declaring a Bean in a JSP Page
        3. Reading Bean Properties
          1. Using the <jsp:getProperty> Action
          2. Using the JSTL Expression Language
          3. Including Images with JSP
        4. Setting Bean Properties
          1. Automatic Type Conversions
      3. 7. Using Custom Tag Libraries and the JSP Standard Tag Library
        1. What Is a Custom Tag Library?
        2. Installing a Custom Tag Library
        3. Declaring a Custom Tag Library
          1. Identifying a Custom Tag Library in a JSP 1.1 Container
        4. Using Actions from a Tag Library
          1. Setting Action Attribute Values
          2. The JSP Standard Tag Library
            1. The JSTL Expression Language
          3. Using Beans or Custom Actions
      4. 8. Processing Input and Output
        1. Reading Request Parameter Values
          1. Accessing Parameter Values with JSTL Actions
          2. Accessing Other Request Data
          3. Capturing Parameter Values Using a Bean
        2. Validating User Input
          1. Validating User Input Using JSTL Actions
          2. Validating User Input Using a Bean
        3. Formatting HTML Output
      5. 9. Error Handling and Debugging
        1. Dealing with Syntax Errors
          1. Element Syntax Errors
          2. JSTL Expression Language Syntax Errors
        2. Debugging a JSP Application
        3. Dealing with Runtime Errors
          1. Catching Exceptions
      6. 10. Sharing Data Between JSP Pages, Requests, and Users
        1. Passing Control and Data Between Pages
          1. Passing Control from One Page to Another
          2. Passing Data from One Page to Another
          3. All Together Now
        2. Sharing Session and Application Data
          1. Session Tracking Explained
          2. Counting Page Hits
          3. URL Rewriting
        3. Online Shopping
          1. Number Formatting
          2. Using a Request Parameter as an Index
          3. Redirect Versus Forward
        4. Memory Usage Considerations
      7. 11. Accessing a Database
        1. Accessing a Database from a JSP Page
          1. Application Architecture Example
          2. Table Example
          3. The DataSource Interface and JDBC Drivers
          4. Reading and Storing Information in a Database
            1. Reading database information
            2. Inserting database information
            3. Updating database information
          5. Generating HTML from a Query Result
          6. Searching for Rows Based on Partial Information
          7. Deleting Database Information
          8. Displaying Database Data over Multiple Pages
            1. Setting an upper limit for the result size
            2. Getting a limited number of rows at a time
            3. Run a query once and display the result over multiple pages
        2. Validating Complex Input Without a Bean
        3. Using Transactions
        4. Application-Specific Database Actions
      8. 12. Authentication and Personalization
        1. Container-Provided Authentication
          1. Authenticating Users
          2. Controlling Access to Web Resources
        2. Application-Controlled Authentication
          1. A Table for Personalized Information
          2. Logging In
            1. Using cookies to remember the username and password
          3. Authentication Using a Database
            1. Creating the validation object
            2. Setting and deleting cookies
            3. Redirect to the application page
          4. Checking for a Valid Session
            1. Providing personalized content
          5. Updating the User Profile
          6. Logging Out
        3. Other Security Concerns
      9. 13. Internationalization
        1. How Java Supports Internationalization and Localization
          1. The Locale Class
          2. Formatting Numbers and Dates
          3. Using Localized Text
        2. Generating Localized Output
          1. Using One Page for Multiple Locales
          2. Using a Separate Page per Locale
        3. A Brief History of Bits
        4. Handling Localized Input
          1. Dealing with Non-Western European Input
      10. 14. Working with XML Data
        1. Generating an XML Response
        2. Transforming XML into HTML
        3. Transforming XML into a Device-Dependent Format
        4. Processing XML Data
          1. Caching Data
          2. Parsing XML Data
          3. Accessing XML Data Using XPath Expressions
      11. 15. Using Scripting Elements
        1. Using page Directive Scripting Attributes
        2. Implicit JSP Scripting Objects
        3. Using Scriptlets
        4. Using Expressions
        5. Using Declarations
          1. jspInit() and jspDestroy()
        6. Mixing Action Elements and Scripting Elements
          1. Using an Expression Element to Set an Attribute
          2. Using JSTL with Request-Time Attribute Values
          3. Accessing Scoped Variables in Scripting Code
        7. Dealing with Scripting Syntax Errors
          1. Scripting Syntax Error Examples
      12. 16. Bits and Pieces
        1. Buffering
        2. Including Page Fragments
        3. Mixing Client-Side and Server-Side Code
          1. Generating JavaScript Code
            1. Using server-side data in JavaScript code
          2. Using Java Applets
        4. Precompiling JSP Pages
        5. Preventing Caching of JSP Pages
        6. Writing JSP Pages as XML Documents
        7. How URIs Are Interpreted
    4. III. JSP in J2EE and JSP Component Development
      1. 17. Web Application Models
        1. The Java 2 Enterprise Edition Model
        2. The MVC Design Model
          1. Using Only JSP
          2. Using Servlets and JSP
          3. Using Servlets, JSP, and EJB
        3. Scalability
          1. Preparing for Distributed Deployment
      2. 18. Combining JSP and Servlets
        1. Servlets, Filters, and Listeners
          1. Servlet Lifecycle
          2. Compiling and Installing a Servlet
          3. Reading a Request
          4. Generating a Response
          5. Using Filters and Listeners
            1. Filters
            2. Listeners
          6. Sharing Data Between the Component Types
        2. Picking the Right Component Type for Each Task
        3. Initializing Shared Resources Using a Listener
        4. Access Control Using a Filter
        5. Centralized Request Processing Using a Servlet
          1. Struts Request Processing Overview
          2. Mapping Application Requests to the Servlet
          3. Dispatching Requests to an Action Class
          4. Implementing the Action Classes
          5. Processing Requests
          6. Calling the Controller Servlet from JSP Pages
        6. Using a Common JSP Error Page
      3. 19. Developing JavaBeans Components for JSP
        1. Beans as JSP Components
          1. JavaBeans Naming Conventions
            1. Handling session events
            2. Using a package name for a bean class
          2. Compiling and Installing a Bean
        2. JSP Bean Examples
          1. Value Beans
          2. Utility Beans
          3. Multithreading Considerations
        3. Unexpected <jsp:setProperty> Behavior
      4. 20. Developing Custom Tag Libraries
        1. Tag Extension Basics
        2. Developing a Simple Action
        3. Developing an Iterating Action
        4. Processing the Action Body
          1. Dealing with Empty Elements
        5. Handling Exceptions
        6. The Tag-Handler Lifecycle and What It Means to You
          1. Providing Default Values for Optional Attributes
          2. Resetting Per-Invocation State
          3. Keeping Expensive Resources for the Lifetime of the Tag Handler Instance
        7. Creating the Tag Library Descriptor
          1. General Library Elements
          2. Validator and Listener Elements
          3. Tag Elements
            1. General tag elements
            2. Variable elements
            3. Attribute elements
            4. Example element
          4. Differences Between a JSP 1.1 and a JSP 1.2 TLD
        8. Packaging and Installing a Tag Library
          1. Making the Tag Library Files Available to the Container
          2. Identifying the Tag Library in a JSP Page
          3. Packaging Multiple Libraries in One JAR File
      5. 21. Advanced Custom Tag Library Features
        1. Developing Cooperating Actions
          1. Using Explicit Parent-Child Cooperation
          2. Using Implicit Cooperation Through Variables
            1. Creating a scripting variable
            2. Using a TagExtraInfo subclass to declare a variable
        2. Validating Syntax
          1. Validation Based on the TLD
          2. Using a TagLibraryValidator
          3. Using a TagExtraInfo Class for Validation
        3. Using a Listener in a Tag Library
        4. Dynamic Attribute Values and Types
          1. Conversions Performed by the Container
          2. Using a PropertyEditor for Conversion
      6. 22. Integrating Custom Code with JSTL
        1. Using the Expression Language in Custom Actions
        2. Setting and Using Configuration Variables
        3. Integrating Custom Conditional Actions
        4. Integrating Custom Iteration Actions
          1. Implementing a Custom Iteration Action
          2. Interacting with an Iteration Action
        5. Integrating Custom I18N Actions
        6. Integrating Custom Database Actions
        7. Using JSTL Tag Library Validators
      7. 23. Database Access Strategies
        1. JDBC Basics
        2. Using Connections and Connection Pools
          1. Using a JDBC 2.0 Optional Package Connection Pool
          2. Making a JDBC 1.0 Connection Pool Behave as a JDBC 2.0 Connection Pool
        3. Making a Connection Pool Available to Application Components
          1. Using an Application Scope Variable
          2. Using JNDI
        4. Using a Generic Database Bean
        5. Developing Application-Specific Database Components
    5. IV. Appendixes
      1. A. JSP Elements Reference
        1. Directive Elements
          1. Include Directive
          2. Page Directive
          3. Taglib Directive
        2. Scripting Elements
          1. Declaration
          2. Expression
          3. Scriptlet
        3. Action Elements
          1. Reference Section
            1. <jsp:fallback>
          2. Reference Section
            1. <jsp:forward>
          3. Reference Section
            1. <jsp:getProperty>
          4. Reference Section
            1. <jsp:include>
          5. Reference Section
            1. <jsp:param>
          6. Reference Section
            1. <jsp:params>
          7. Reference Section
            1. <jsp:plugin>
          8. Reference Section
            1. <jsp:setProperty>
          9. Reference Section
            1. <jsp:useBean>
          10. Custom Actions
        4. Comments
        5. Escape Characters
      2. B. JSTL Actions and API Reference
        1. JSTL Library URIs and Default Prefixes
        2. Core Library Actions
          1. <c:catch>
          2. <c:choose>
          3. <c:forEach>
          4. <c:forTokens>
          5. <c:if>
          6. <c:import>
          7. <c:otherwise>
          8. <c:out>
          9. <c:param>
          10. <c:redirect>
          11. <c:remove>
          12. <c:set>
          13. <c:url>
          14. <c:when>
        3. Internationalization and Formatting Actions
          1. <fmt:bundle>
          2. <fmt:formatDate>
          3. <fmt:formatNumber>
          4. <fmt:message>
          5. <fmt:param>
          6. <fmt:parseDate>
          7. <fmt:parseNumber>
          8. <fmt:requestEncoding>
          9. <fmt:setBundle>
          10. <fmt:setLocale>
          11. <fmt:setTimeZone>
          12. <fmt:timeZone>
        4. Database Access Actions
          1. <sql:dateParam>
          2. <sql:param>
          3. <sql:query>
          4. <sql:setDataSource>
          5. <sql:transaction>
          6. <sql:update>
        5. XML Processing Actions
          1. <x:choose>
          2. <x:forEach>
          3. <x:if>
          4. <x:otherwise>
          5. <x:out>
          6. <x:param>
          7. <x:parse>
          8. <x:set>
          9. <x:transform>
          10. <x:when>
        6. Support and Utility Types
          1. ConditionalTagSupport
          2. LocaleSupport
          3. LocalizationContext
          4. LoopTag
          5. LoopTagStatus
          6. LoopTagSupport
          7. Result
          8. ResultSupport
          9. SQLExecutionTag
        7. Configuration Settings
          1. Data Source
          2. Fallback Locale
          3. Locale
          4. Localization Context
          5. Max Rows
          6. Time Zone
      3. C. JSTL Expression Language Reference
        1. Syntax
          1. Literals
          2. Keywords and Reserved Words
        2. Variables
          1. Implicit Variables
        3. Data Types
          1. Coercion Rules
        4. Expressions and Operators
          1. Operand Coercing Rules
            1. Property and array accessor operators
            2. Arithmetic operators
            3. Relational operators
            4. Logical operators
            5. Empty operator
      4. D. JSP API Reference
        1. Implicit Variables
          1. application
          2. config
          3. exception
          4. out
          5. page
          6. pageContext
          7. request
          8. response
          9. session
        2. Other Servlet Types Accessible Through Implicit Variables
          1. Cookie
          2. RequestDispatcher
        3. Tag Handler Types
          1. BodyContent
          2. BodyTag
          3. BodyTagSupport
          4. IterationTag
          5. Tag
          6. TagAttributeInfo
          7. TagData
          8. TagExtraInfo
          9. TagInfo
          10. TagLibraryInfo
          11. TagSupport
          12. TagVariableInfo
          13. TryCatchFinally
          14. VariableInfo
        4. Tag Library Validation Types
          1. PageData
          2. TagLibraryValidator
          3. ValidationMessage
        5. Other JSP Types
          1. HttpJspPage
          2. JspEngineInfo
          3. JspException
          4. JspFactory
          5. JspPage
          6. JspTagException
      5. E. Book Example Custom Actions and API Reference
        1. Generic Custom Actions
          1. <ora:addCookie>
          2. <ora:debug>
          3. <ora:fileWrite>
          4. <ora:forward>
          5. <ora:ifContains>
          6. <ora:ifUserInRole>
          7. <ora:ifValidEmailAddr>
          8. <ora:invalidateSession>
          9. <ora:menuItem>
          10. <ora:noCache>
          11. <ora:param>
          12. <ora:setHeader>
        2. Generic Utility Classes
          1. ConnectionPool
          2. ConnectionWrapper
          3. CookieUtils
          4. DataSourceFactory
          5. DataSourceWrapper
          6. StringFormat
          7. SQLCommandBean
      6. F. Web Application Structure and Deployment Descriptor Reference
        1. Web Application File Structure
          1. Placing Java Class Files in the Right Directory
        2. Web Application Deployment Descriptor
          1. <icon>, <display-name>, and <description>
          2. <distributable>
          3. <context-param>
          4. <filter>
          5. <filter-mapping>
          6. <listener>
          7. <servlet>
          8. <servlet-mapping>
          9. <session-config>
          10. <mime-mapping>
          11. <welcome-file-list>
          12. <error-page>
          13. <taglib>
          14. <resource-env-ref>
          15. <resource-ref>
          16. <security-constraint>
          17. <login-config>
          18. <security-role>
          19. <env-entry>
          20. <ejb-ref>
          21. <ejb-local-ref>
          22. Example Application Deployment Descriptor
        3. Creating a WAR File
    6. Index
    7. Colophon