Provides students with in-depth, hands-on coverage of servlets 2.2 and JSP 1.1.
Provides students with important advanced coverage.
Provides students with guidelines for use of servlets and JSP and discusses every standard JSP element.
Familiarizes students with sharing beans, generating Excel spreadsheets and defining custom JSP tag libraries.
Shows students how to use HTML forms for collecting data from users.
Shows students its use in communicating with relational databases.
Shows students how to use them as servlet front ends.
Provides students with a handy syntax and usage summary.
Servlets and JavaServer Pages provide a powerful, efficient, portable, and secure alternative to CGI programming for developing professional e-commerce sites and other Web-enabled applications. Here's all you need to leverage the latest J2EE servlet 2.2 and JSP 1.1 standards: real-world insight, advanced techniques, industrial-strength code, and hands-on coverage of three top servlet/JSP engines, including Apache Tomcat.
Every Core Series book:
Core Servlets and JavaServer Pages delivers:
Click here for a sample chapter for this book: 0130893404.pdf
I. SERVLETS 2.1 AND 2.2.1. Overview of Servlets and JavaServer Pages.
Servlets. The Advantages of Servlets Over "Traditional" CGI. JavaServer Pages. The Advantages of JSP. Installation and Setup.2. First Servlets.
Basic Servlet Structure. A Simple Servlet Generating Plain Text. A Servlet That Generates HTML. Packaging Servlets. Simple HTML-Building Utilities. The Servlet Life Cycle. An Example Using Initialization Parameters. An Example Using Servlet Initialization and Page Modification Dates. Debugging Servlets. WebClient: Talking to Web Servers Interactively.3. Handling the Client Request: Form Data.
The Role of Form Data. Reading Form Data from Servlets. Example: Reading Three Explicit Parameters. Example: Reading All Parameters. A Résumé Posting Service. Filtering Strings for HTML-Specific Characters.4. Handling the Client Request: HTTP Request Headers.
Reading Request Headers from Servlets. Printing All Headers. HTTP 1.1 Request Headers. Sending Compressed Web Pages. Restricting Access to Web Pages.5. Accessing the Standard CGI Variables.
Servlet Equivalent of CGI Variables. A Servlet That Shows the CGI Variables.6. Generating the Server Response: HTTP Status Codes.
Specifying Status Codes. HTTP 1.1 Status Codes and Their Purpose. A Front End to Various Search Engines.7. Generating the Server Response: HTTP Response Headers.
Setting Response Headers from Servlets. HTTP 1.1 Response Headers and Their Meaning. Persistent Servlet State and Auto-Reloading Pages. Using Persistent HTTP Connections. Using Servlets to Generate GIF Images.8. Handling Cookies.
Benefits of Cookies. Some Problems with Cookies. The Servlet Cookie API. Examples of Setting and Reading Cookies. Basic Cookie Utilities. A Customized Search Engine Interface.9. Session Tracking.
The Need for Session Tracking. The Session Tracking API. A Servlet Showing Per-Client Access Counts. An On-Line Store Using a Shopping Cart and Session Tracking.
II. JAVASERVER PAGES.10. JSP Scripting Elements.
Scripting Elements. JSP Expressions. JSP Scriptlets. JSP Declarations. Predefined Variables.11. The JSP page Directive: Structuring Generated Servlets.
The Import Attribute. The ContentType Attribute. The IsThreadSafe Attribute. The Session Attribute. The Buffer Attribute. The Autoflush Attribute. The Extends Attribute. The Info Attribute. The ErrorPage Attribute. The IsErrorPage Attribute. The Language Attribute. XML Syntax for Directives.12. Including Files and Applets in JSP Documents.
Including Files at Page Translation Time. Including Files at Request Time. Including Applets for the Java Plug-In.13. Using JavaBeans with JSP.
Basic Bean Use. Example: StringBean. Setting Bean Properties. Sharing Beans.14. Creating Custom JSP Tag Libraries.
The Components That Make Up a Tag Library. Defining a Basic Tag. Assigning Attributes to Tags. Including the Tag Body. Optionally Including the Tag Body. Manipulating the Tag Body. Including or Manipulating the Tag Body Multiple Times. Using Nested Tags.15. Integrating Servlets and JSP.
Forwarding Requests. Example: An On-Line Travel Agent. Including Static or Dynamic Content. Example: Showing Raw Servlet and JSP Output. Forwarding Requests From JSP Pages.
III. SUPPORTING TECHNOLOGIES.16. Using HTML Forms.
How HTML Forms Transmit Data. The FORM Element. Text Controls. Push Buttons. Check Boxes and Radio Buttons. Combo Boxes and List Boxes. File Upload Controls. Server-Side Image Maps. Hidden Fields. Grouping Controls. Controlling Tab Order. A Debugging Web Server.17. Using Applets as Servlet Front Ends.
Sending Data with GET and Displaying the Resultant Page. A Multisystem Search Engine Front End. Sending Data with GET and Processing the Results Directly (HTTP Tunneling). A Query Viewer That Uses Object Serialization and HTTP Tunneling. Sending Data by POST and Processing the Results Directly (HTTP Tunneling). An Applet That Sends POST Data. Bypassing the HTTP Server.18. JDBC and Database Connection Pooling.
Basic Steps in Using JDBC. Basic JDBC Example. Some JDBC Utilities. Applying the Database Utilities. An Interactive Query Viewer. Prepared Statements (Precompiled Queries). Connection Pooling. Connection Pooling: A Case Study. Sharing Connection Pools.Appendix: Servlet and JSP Quick Reference.
Overview of Servlets and JavaServer Pages. First Servlets. Handling the Client Request: Form Data. Handling the Client Request: HTTP Request Headers. Accessing the Standard CGI Variables. Generating the Server Response: HTTP Status Codes. Generating the Server Response: HTTP Response Headers. Handling Cookies. Session Tracking. JSP Scripting Elements. The JSP Page Directive: Structuring Generated Servlets. Including Files and Applets in JSP Documents. Using JavaBeans with JSP. Creating Custom JSP Tag Libraries. Integrating Servlets and JSP. Using HTML Forms. Using Applets As Servlet Front Ends. JDBC and Database Connection Pooling.Index.
In early 1996, I started using the Java programming language for the majority of my software development work. I did some CGI programming and even worked a little with the early servlet versions, but for the most part I did desktop and client-side applications. Over the last couple of years, however, there has been a growing emphasis on server-side applications, so I became more serious about servlets and JavaServer Pages. In the past year, there has been a virtual stampede toward the technology among developers, server vendors, and the authors of the Java platform specifications. So much so, in fact, that the technology is rapidly becoming the standard tool for building dynamic Web sites and connecting Web front ends to databases and applications on a server.
Unfortunately, however, it was extremely difficult to find good practical advice on servlet and JSP development. I found a number of servlet books, but only a handful of them covered recent versions of the specification, advanced techniques, or reflected real-world experience. The few that did, if they covered JSP at all, hadn't caught up to JSP 1.0, let alone JSP 1.1. Since JSP is a better fit than servlets for many situations, what good was a servlet book that didn't also cover JSP? In the last couple of months, some JSP books have started coming out. But the bulk of them don't cover servlets. What good is that? Since an integral part of JavaServer Pages is the use of scripting elements to create servlet code, you can't do effective JSP development without a thorough understanding of servlets. Besides, most real-world sites don't use just one of the two technologies; they combine them both. Finally, as I discovered when I started teaching servlet and JSP development to my students in the Johns Hopkins part-time graduate program (most of whom were professional software developers), few programmers were already comfortable with HTTP 1.1, HTML forms, and JDBC, three critical supporting technologies. Telling them to get a separate book for each of these areas was hardly reasonable: that brought to five the number of books programmers needed if they were going to do serious servlet/JSP development.
So, in mid-1999, I put together a short servlet and JSP tutorial with a few dozen examples, put it on the Web, and tried out the material in a couple of my courses. The response was overwhelming. After only a few months, I was getting several thousand visitors a day to the tutorial along with a myriad of requests to expand the coverage of the material. I eventually bowed to the inevitable and started writing. This book is the result. I hope you find it useful.
This book is aimed at serious software developers. This is not a book that touts the potential of e-commerce or pontificates about how Web-enabled applications will revolutionize your business. Instead, it is a hands-on book aimed at helping programmers who are already convinced of the need for dynamic Web sites get started building them right away. In showing how to build these sites, I try to illustrate the most important approaches and warn you of the most common pitfalls. Along the way, I include plenty of working code: more than a hundred documented Java classes, for instance. I try to give detailed examples of the most important and frequently used features, summarize the lesser-used ones, and refer you to the APIs (available on-line) for a few of the rarely used ones.
Nor is this a book that skims dozens of technologies at a high level. Although I don't claim that this is a definitive reference on every technology it touches on (e.g., there are a number of books this size just on JDBC), if the book covers a topic, it does so in enough detail for you to sit down and start writing real programs. The one exception to this rule is the Java programming language itself. Although I don't assume any familiarity with server-side programming, I do expect you to be familiar with the basics of Java language development. If you're not, you will need to pick up a good tutorial like Core Java, Core Web Programming, or Thinking in Java.
A word of caution, however. Nobody becomes a great developer just by reading. You have to write some real code, too. The more, the better. In each chapter, I suggest that you start by making a simple program or a small variation of one of the examples given, then strike off on your own with a more significant project. Skim the sections you don't plan on using right away, then come back when you are ready to try them out.
If you do this, you should quickly develop the confidence to handle the real-world problems that brought you here in the first place. You should be able to decide where servlets apply well, where JSP is better, and where a combination is best. You should not only know how to generate HTML content, but you should also understand building other media types like GIF images or Excel spreadsheets. You should understand HTTP 1.1 well enough to use its capabilities to enhance the effectiveness of your pages. You should have no qualms about developing Web interfaces to your corporate databases, using either HTML forms or applets as front ends. You should be able to spin off complex behaviors into JavaBeans components or custom JSP tag libraries, then decide when to use these components directly and when to start requests with servlets that set things up for separate presentation pages. You should have fun along the way. You should get a raise.
This book is divided into three parts: Servlets, JavaServer Pages, and Supporting Technologies.
Part I covers servlet development with the 2.1 and 2.2 specifications. Although version 2.2 (along with JSP 1.1) is mandated by the Java 2 Platform, Enterprise Edition (J2EE), many commercial products are still at the earlier releases, so it is important to understand the differences. Also, although servlet code is portable across a huge variety of servers and operating systems, server setup and configuration details are not standardized. So, I include specific details for Apache Tomcat, Sun's JavaServer Web Development Kit (JSWDK), and the Java Web Server. Servlet topics include:
JSP provides a convenient alternative to servlets for pages that mostly consist of fixed content. Part II covers the use of JavaServer Pages version 1.0 and 1.1. JSP topics include:
Part III covers three topics that are commonly used in conjunction with servlets and JSP: HTML forms, applets talking to servlets, and JDBC. Topics include:
The book has a companion Web site at http://www.coreservlets.com/. This free site includes: