You are previewing Servlet & JSP: A Tutorial, Second Edition.
O'Reilly logo
Servlet & JSP: A Tutorial, Second Edition

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.1 and JSP 2.3, this book explains the important proogramming 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 lots 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 - Expression Language 3.0 - JSTL - Custom tags and tag files - Filters and listeners - Application design - Dependency injection - File upload and programming file download - Asynchronous processing - Security - Deployment and the deployment descriptor - Dynamic registration - Servlet container initializers - WebSocket and JPA This book is for you if you need one written with clarity and readability in mind.

Table of Contents

  1. 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
  2. Chapter 1: Getting Started
    1. Downloading and Installing NetBeans
    2. Creating A Web Project with NetBeans
    3. Troubleshooting
    4. Creating A Servlet
    5. Behind the Scenes
    6. Starting, Stopping and Restarting Tomcat
    7. Monitoring HTTP Traffic
    8. Summary
  3. Chapter 2: The Servlet API
    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. HttpServletRequest
    11. Working with HTML Forms
    12. Using the Deployment Descriptor
    13. Summary
  4. Chapter 3: Session Management
    1. Hidden Fields
    2. Cookies
    3. HttpSession Objects
    4. Notifying the Browser the HttpSession Has Expired
    5. Summary
  5. Chapter 4: JavaServer Pages
    1. An Overview of JSP
    2. Comments
    3. Implicit Objects
    4. Directives
    5. Scripting Elements
    6. Summary
  6. Chapter 5: The Expression Language
    1. A Brief History of the Expression Language
    2. The Expression Language Syntax
    3. Accessing JavaBeans
    4. EL Implicit Objects
    5. Using Other EL Operators
    6. Referencing Static Fields and Methods
    7. Creating Sets, Lists and Maps
    8. Accessing List Elements and Map Entries
    9. Manipulating Collections
    10. Formatting Collections
    11. Formatting Numbers
    12. Formatting Dates
    13. Configuring the EL in JSP 2.0 and Later Versions
    14. Summary
  7. Chapter 6: JSTL
    1. Downloading JSTL
    2. JSTL Libraries
    3. General-Purpose Actions
    4. Conditional Actions
    5. Iterator Actions
    6. Formatting Actions
    7. Functions
    8. Summary
  8. Chapter 7: 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
  9. Chapter 8: Tag Files
    1. Introduction to Tag Files
    2. Your First Tag File
    3. Tag File Directives
    4. doBody
    5. invoke
    6. Summary
  10. Chapter 9: Listeners
    1. Listener Interfaces and Registration
    2. Servlet Context Listeners
    3. Session Listeners
    4. ServletRequest Listeners
    5. Summary
  11. Chapter 10: 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
  12. Chapter 11: 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. Dependency Injection
    7. Summary
  13. Chapter 12: File Upload
    1. Client Side Programming
    2. Server Side Programming
    3. Upload Servlet Example
    4. Multiple Uploads
    5. Upload Clients
    6. Summary
  14. Chapter 13: File Download
    1. File Download Overview
    2. Example 1: Hiding A Resource
    3. Example 2: Preventing Cross-Referencing
    4. Summary
  15. Chapter 14: Java Database Connectivity
    1. Introduction to JDBC
    2. Four Steps to Data Access
    3. Using Java DB
    4. Obtaining Auto-Generated Keys
    5. Managing Databases with NetBeans
    6. The Data Access Object (DAO) Pattern
    7. Connection Pooling
    8. Servlet Meets JDBC
    9. Reading the Metadata
    10. Summary
  16. Chapter 15: Java Persistence API
    1. JPA Overview
    2. Creating Entities
    3. Managing Entities
    4. Working with Queries
    5. Using NetBeans to Deal with JPA
    6. Servlet Meets JPA
    7. Summary
  17. Chapter 16: JavaMail
    1. JavaMail Overview
    2. Sending Emails with JavaMail
    3. Sending Emails with Apache Commons Email
    4. Using Gmail's SMTP Server
    5. WebMail
    6. Summary
  18. Chapter 17: Decorating Requests and Responses
    1. The Decorator Pattern
    2. Servlet Wrapper Classes
    3. Example: AutoCorrect Filter
    4. Summary
  19. Chapter 18: Asynchronous Processing
    1. Overview
    2. Writing Async Servlets and Filters
    3. Writing Async Servlets
    4. Async Listeners
    5. ReadListener
    6. WriteListener
    7. Summary
  20. Chapter 19: Security
    1. Authentication and Authorization
    2. Authentication Methods
    3. SSL and TLS
    4. Programmatic Security
    5. Summary
  21. Chapter 20: Deployment
    1. Deployment Descriptor Overview
    2. Deployment
    3. Web Fragments
    4. Summary
  22. Chapter 21: WebSocket
    1. WebSocket Overview
    2. Java WebSocket API
    3. Creating a WebSocket ServerEndPoint
    4. An Echo Server
    5. Sending Messages to All Users
    6. Using User Properties
    7. Using Configurators
    8. Tracking Session Expiration in the Browser
    9. Summary
  23. Chapter 22: Dynamic Registration and Servlet Container Initializers
    1. Dynamic Registration
    2. Servlet Container Initializers
    3. Summary
  24. Chapter 23: Introduction to Spring MVC
    1. Downloading Spring Framework
    2. Benefits of Spring MVC
    3. Spring MVC DispatcherServlet
    4. The Controller Interface
    5. Your First Spring MVC Application
    6. The View Resolver
    7. Annotation-based Controllers
    8. Writing Request-Handling Methods
    9. Using An Annotation-Based Controller
    10. Summary
  25. Chapter 24: Introduction to Struts 2
    1. The Benefits of Struts 2
    2. How Struts 2 Works
    3. Interceptors
    4. Configuration Files
    5. A Simple Struts 2 Application
    6. Summary
  26. Appendix A: HTML
    1. Getting Started
    2. Working with Text
    3. Links
    4. Images
    5. Lists
    6. Tables
    7. Forms
    8. Multimedia
  27. Appendix B: Cascading Style Sheets
    1. Overview
    2. Applying Styles
    3. Web Colors
    4. Selectors
    5. Styling Text
    6. Styling Boxes
    7. Styling Links
    8. Styling Lists
    9. Styling Tables
    10. Styling Forms
  28. Appendix C: Tomcat
    1. Downloading and Configuring Tomcat
    2. Starting and Stopping Tomcat
    3. Defining A Context
    4. Defining A Resource
    5. Installing TLS Certificates
  29. Appendix D: Web Annotations
    1. HandlesTypes
    2. HttpConstraint
    3. HttpMethodConstraint
    4. MultipartConfig
    5. ServletSecurity
    6. WebFilter
    7. WebInitParam
    8. WebListener
    9. WebServlet
  30. Appendix E: TLS Certificates
    1. Certificate Overview
    2. The KeyTool Program
  31. Appendix F: The Spring Framework
    1. Dependency Injection
    2. XML-Based Spring Configuration
    3. Using the Spring IoC Container