You are previewing Servlet and JSP: A Tutorial.
O'Reilly logo
Servlet and JSP: A Tutorial

Book Description

Servlet and JavaServer Pages (JSP) are the underlying technologies for developing web applications in Java. They are essential for any programmer to master in order to effectively use frameworks such as JavaServer Faces, Struts 2, or Spring MVC.

Covering Servlet 3.0 and JSP 2.2, this book explains the important programming concepts and design models in Java web development as well as related technologies and new features in the latest versions of Servlet and JSP. With comprehensive coverage and a lot of examples, this book is a guide to building real-world applications. Topics discussed in this book include:

  • The Servlet API

  • JSP syntax and scripting elements

  • Session management

  • The Expression Language

  • JavaServer Pages Standard Tag Library (JSTL)

  • Custom tags and tag files

  • Filters and listeners

  • Application design

  • Connection pooling

  • Dependency injection

  • File upload and programmatic file download

  • Asynchronous processing

  • Security

  • Deployment and the deployment descriptor

  • Dynamic registration

  • Servlet container initializers

Table of Contents

  1. Cover Page
  2. Title Page
  3. Copyright Page
  4. Table of Contents
  5. Introduction
    1. Servlet/JSP Application Architecture
    2. The Hypertext Transfer Protocol (HTTP)
    3. About This Book
    4. Downloading the Sample Applications
    5. Choosing a Framework
  6. Chapter 1: Servlets
    1. Servlet API Overview
    2. Servlet
    3. Writing A Basic Servlet Application
    4. ServletRequest
    5. ServletResponse
    6. ServletConfig
    7. ServletContext
    8. GenericServlet
    9. HTTP Servlets
    10. Working with HTML Forms
    11. Using the Deployment Descriptor
    12. Summary
  7. Chapter 2: Session Management
    1. URL Rewriting
    2. Hidden Fields
    3. Cookies
    4. HttpSession Objects
    5. Summary
  8. Chapter 3: JavaServer Pages
    1. An Overview of JSP
    2. Comments
    3. Implicit Objects
    4. Directives
    5. Scripting Elements
    6. Actions
    7. Summary
  9. Chapter 4: The Expression Language
    1. The Expression Language Syntax
    2. Accessing JavaBeans
    3. EL Implicit Objects
    4. Using Other EL Operators
    5. Using the Expression Language
    6. Configuring the EL in JSP 2.0 and Later Versions
    7. Summary
  10. Chapter 5: JSTL
    1. Downloading JSTL
    2. JSTL Libraries
    3. General-Purpose Actions
    4. Conditional Actions
    5. Iterator Actions
    6. Formatting Actions
    7. Functions
    8. Summary
  11. Chapter 6: Writing Custom Tags
    1. Custom Tag Overview
    2. Simple Tag Handlers
    3. SimpleTag Example
    4. Handling Attributes
    5. Manipulating the Tag Body
    6. Writing EL Functions
    7. Distributing Custom Tags
    8. Summary
  12. Chapter 7: Tag Files
    1. Introduction to Tag Files
    2. Your First Tag File
    3. Tag File Directives
    4. doBody
    5. invoke
    6. Summary
  13. Chapter 8: Listeners
    1. Listener Interfaces and Registration
    2. Servlet Context Listeners
    3. Session Listeners
    4. ServletRequest Listeners
    5. Summary
  14. Chapter 9: Filters
    1. The Filter API
    2. Filter Configuration
    3. Example 1: Logging Filter
    4. Example 2: Image Protector Filter
    5. Example 3: Download Counter Filter
    6. Filter Order
    7. Summary
  15. Chapter 10: Application Design
    1. Model 1 Overview
    2. Model 2 Overview
    3. Model 2 with A Servlet Controller
    4. Model 2 with A Filter Dispatcher
    5. Validators
    6. Database Access
    7. Dependency Injection
    8. Summary
  16. Chapter 11: File Upload
    1. Client Side Programming
    2. Server Side Programming
    3. Upload Servlet Example
    4. Multiple Uploads
    5. Upload Clients
    6. Summary
  17. Chapter 12: File Download
    1. File Download Overview
    2. Example 1: Hiding A Resource
    3. Example 2: Preventing Cross-Referencing
    4. Summary
  18. Chapter 13: Decorating Requests and Responses
    1. The Decorator Pattern
    2. Servlet Wrapper Classes
    3. Example: AutoCorrect Filter
    4. Summary
  19. Chapter 14: Asynchronous Processing
    1. Overview
    2. Writing Async Servlets and Filters
    3. Writing Async Servlets
    4. Async Listeners
    5. Summary
  20. Chapter 15: Security
    1. Authentication and Authorization
    2. Authentication Methods
    3. Secure Sockets Layer (SSL)
    4. Programmatic Security
    5. Summary
  21. Chapter 16: Deployment
    1. Deployment Descriptor Overview
    2. Deployment
    3. Web Fragments
    4. Summary
  22. Chapter 17: Dynamic Registration and Servlet Container Initializers
    1. Dynamic Registration
    2. Servlet Container Initializers
    3. Summary
  23. Chapter 18: Introduction to Struts 2
    1. The Benefits of Struts 2
    2. How Struts 2 Works
    3. Interceptors
    4. Struts 2's Configuration Files
    5. A Simple Struts Application
    6. Summary
  24. Appendix A: Tomcat
    1. Downloading and Configuring Tomcat
    2. Starting and Stopping Tomcat
    3. Defining A Context
    4. Defining A Resource
    5. Installing SSL Certificates
  25. Appendix B: Web Annotations
    1. HandlesTypes
    2. HttpConstraint
    3. HttpMethodConstraint
    4. MultipartConfig
    5. ServletSecurity
    6. WebFilter
    7. WebInitParam
    8. WebListener
    9. WebServlet
  26. Appendix C: SSL Certificates
    1. Certificate Overview
    2. The KeyTool Program
  27. Index