Dear All,
Thanks for all the questions and comments. I'll reply to every one of them in a moment, but first I'd like to use this opportunity to write a brief introduction to this book.
"How
Tomcat Works" explains the internal workings of Tomcat. It does not require you to be an expert in Tomcat to understand it. In fact, this book invites you to write Tomcat from scratch. How is it possible? Tomcat is so complex, you might say. That's true, but this book does not try to explain everything in one go.
Chapter 1 starts off with a discussion of
Java sockets and shows how to use it to build a simple Java web server that can only display static pages. You know how to read files in Java, don't you? Well, then you can read (static) HTML files. The application is so simple that if you understand how sockets work (explained at the beginning of the chapter),
you should be able to understand it. In fact, it only has 3 small classes.
Chapter 2 builds on the application developed in Chapter 1. The application in Chapter 2 is a modified version of the web server in Chapter 1. It adds one function so that the web server can also load and run a
servlet. So now the web server has evolved into a servlet container. Because it is so primitive, it can only run very simple servlets. Of course this chapter also explains how the application works. If you have written a servlet before, you know that the javax.servlet.Servlet interface has a lifecycle method named service where you put the code to be executed when the servlet is invoked. This chapter teaches you how to load a servlet class, instantiate it and call its service method. Don't worry about the other 2 lifecycle methods (init and destroy) for now, they will be discussed in the next chapters.
Chapter 3 enhances the application in Chapter 2. You know that the Servlet interface's service method accepts 2 arguments as indicated by its signature:
public void service(HttpServletRequest request, HttpServletResponse response)
The application in Chapter 3 shows how to create the HttpServletRequest and HttpServletResponse objects for every HTTP request that invokes the servlet. (in chapter 2 the application calls the servlet's service method by passing null to its 2 arguments.) Now you see, the application is slightly smarter than the previous one.
And, after Chapter 20, you'll get Tomcat.
By now, I hope you understand the approach I used when writing this book and believe me that you do not need to be a Java expert to follow the book topics. Every Java feature that will be used in an application will be first explained in the corresponding chapter. For example, before discussing the use of JMX in Tomcat, the chapter explains what JMX is and how to use it. Before explaining how Digester is used to parse web.xml files, the chapter explains what Digester is and let you play with a simple application that uses Digester.
Now, is there any use of understanding how Tomcat works?
I received emails that asked me this question soon after Richard Monson-Haefel (the author of Enterprise Java Beans by O'Reilly) mentioned this book in his blog (
http://weblogs.java.net/pub/wlg/1372). I would simply say yes.
First of all, by understanding how a servlet container works, you will be able to write better servlet/JSP applications. It will probably answer some of the questions you have been asking too, such as whether or not a container creates one instance or many instances of a servlet, how a servlet container manages sessions, how it creates request and response objects, why we cannot modify the request parameter values, etc.
Also, Tomcat is a real life Java application with such an elegant design. Knowing such an application was designed and built helps any Java programmers and architects. For example, this book shows how Tomcat uses a pool of request objects and at the same time guarantees
thread safety. The book also teaches what JMX is and how to use it.
In addition, you will be able to customize Tomcat and build Tomcat components. To demonstrate this point, I have actually written a module for helping
Struts programmers develop Struts applications more rapidly. The module reloads your Struts application when your struts-config.xml has changed. Better still, you only need 33 lines of code to write this module. That's right, writing Tomcat custom components can be very easy. You can download the module from the book's website.
Finally, I'd like to invite you to download 6 sample chapters from the book, on
www.brainysoftware.com. I hope you enjoy it.
Cheers,
Budi
[ September 15, 2004: Message edited by: Budi Kurniawan ]
[ September 15, 2004: Message edited by: Budi Kurniawan ]