Enterprise Java Servlets with Cdrom
Jeff M. Genender · Addison-Wesley Longman Publishing Co., Inc. eBooks · 2001
From the Book: This book is intended for intermediate and advanced Java servlet developers. It is not an introductory book about servlets; there are already a number of excellent books on that topic on the market. If you are only beginning to work with Java servlets, consider purchasing Inside Servlets: Server-Side Programming for the Java Platform, Second Edition (2001), by Dustin R. Callaway, and/or Java Servlet Programming, Second Edition (2001) by Jason Hunter, with William Crawford. Inside Servlets is an excellent book about Java servlets and is a good companion for this book. Callaway's book is easy to read, flows well, has basic and advanced sections, and gives an excellent introduction to servlets, teaching you all you need to know to write Java servlet applications. Java Servlet Programming covers a broad range of Java servlet topics. Although it did not seem that way at the time, it was while working for one of my clients that I happened on a most fortunate set of circumstances. In mid-1999, my team of developers inherited a servlet-based Web application from a previous team. The application was a workflow application to automate travel requests and authorizations that had been slammed together in a short period of time and then thrown over the wall to the company. The application's documentation was sparse, the code's database was a mess, the functionality was just basic at best, and the structure and flow were barely functional and nonscalable. To clean it up, my team worked on the application for a considerable period of time, nearly double the time it took the original developers to code it. It was during this process that I began to more fully understand servlet architecture, including the best way to code applications so that it is possible to add functionality more quickly, to make scalability and reliability more certain, and to ensure that future maintenance of code is simpler. After revamping the entire application, my team suddenly realized what we had--the basis for a framework and architecture that others could use to create robust, scalable, extensible, well-documented servlets. At the client's company, the scripting language of choice was ASP and a smattering of server-side JavaScript. Managers were skeptical about Java; they were convinced that a Java programming language application would take longer to write than an ASP application. We were racing against time to prove that Java servlets could be created just as fast as scripted solutions. We had to beat the ASP guys in terms of time-to-market for applications, as well as make our projects more reliable, scalable, and extensible. We gave ourselves a target of three weeks--three weeks in which to create an entire expense-reporting application. But instead of diving right into the code, we sat down and planned out a base-servlet architecture, something we could use to create this application, as well as subsequently. We wanted to have something on which to build future applications, all the while improving the base from which we worked. We came up with a base servlet from which all servlets would be created. So as not to make the same mistakes the consulting company had made, we were always mindful of what we learned while cleaning up the travel application. We wanted to be sure that we would need to code the application only once, and that we could easily add more functionality, as needed, later. The end product was completed in just over a week, and the expense application was completed a week and a half later, just as quickly as an ASP team could have done the work. The application was stable, reliable, and extensible, and it formed a framework for all future projects. It was at that moment that I started to talk about writing this book, to pass on what we had learned. As my team talked with other developers and mentioned what we had built, invariably they asked for the code. The architecture provided so much functionality right out of the box that it didn't make sense to code servlets from scratch anymore. As we continued to develop applications on top of the base servlet and to augment it with many other useful enterprise-scale enhancements, my interest in writing the book grew. In the intervening months before this book was done, my team didn't rest on its laurels. We pressed on and built a servlet architecture that surely will be valuable for every corporate Java developer. This is not the right way to build servlets, merely a right way. While other servlet architectures may work well (a select few may even work better), the ideas in this book certainly will improve any architecture. My hope is simply that I can pass on what my team learned so that your applications will be better, faster, more reliable, and easier to code and maintain. Enterprise Java™ Servlets is not intended to compete with any other Java-based technology, such as Enterprise JavaBeans (EJBs) and/or JavaServer Pages (JSPs), but to complement them. Because many JSP-based applications delegate the more intensive processing to servlets, the techniques here can be applied and used in this environment. In addition, EJBs are now used to facilitate many aspects of server-side processing. In our world of e-commerce applications, however, we still use servlets as the interface to the Enterprise JavaBeans; thus many of the techniques in this book will be useful. Because servlets are the center of Java-based server technologies, either through the compilation or delegation of a JSP page or as an interface to EJBs, this book shows some effective and efficient techniques for developing servlets in an enterprise environment. There are many excellent books about JSPs and EJBs, so I do not need to describe how we use these technologies with servlets; other books do a fine job of that. Instead, this book discusses the problems and issues that developers will run into when developing servlets, as well as development methods that can be implemented to streamline how servlets execute. This by no means prevents one from using these techniques when developing servlets with JSPs or EJBs, and I hope you will find them useful when you are writing enterprise applications.