This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
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:
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.
[ September 15, 2004: Message edited by: Budi Kurniawan ] [ September 15, 2004: Message edited by: Budi Kurniawan ]
Author of <a href="http://www.amazon.com/exec/obidos/ASIN/097521280X/ref=jranch-20" target="_blank" rel="nofollow">How Tomcat Works</a>
I'd just like to add my welcome to the authors, and say that from the above introduction it sounds like an excellent way to approach a complicated subject. As soon as I can read the sample chapters I'll probably have lots more to ask about!
Mike<br />SCJP 1.4<br />----------------------------<br />firstname.lastname@example.org<br />----------------------------<br />There are 10 types of people<br />in the world. Those that <br />understand binary, and those<br />that don't.
Originally posted by Budi Kurniawan: 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.
Do u have plan to write a kinda "How Struts Works" in the future? Or are there any other upcoming books from BrainySoftware?
Thanks for being here, clearing our doubts on the book's contents...
Although I'm still relatively new to the JAVA world and programming in general, I see a very valid need to understand Tomcat inside and out. I would love to become an "expert" in Tomcat. As you can tell from my post regarding connection pooling - I have a long way to go!
I appreciate you taking the time to respond to our questions (and I hope you can help me solve my problem) as well as offering your book for giveaway.
welcome, mr.Budi Kurniawan , i just wondering , whether would you come out the "jboss howto work" book
Ko Ko Naing
Joined: Jun 08, 2002
Originally posted by gayathri sridhar: I thought Struts in Action itself was too indepth!
But if I am not wrong, that book does not discuss about the stuff inside Struts... The book is about "How to use Struts", rather than "How Struts Works"... So I'm just wondering if Budi has some plans to publish such book in the future or not...