Slashdot Mirror


Web Development With JSP

This "dynamic content" thing doesn't seem to be going away, does it? Web sites need to get smarter to handle the types of content that at least some people want to see on them these days, and the coders and designers behind them need the tools to make them so. Accordingly, Gavin Bong crafted this review of Web Development with JSP, which may be one of the tools you need.

Web Development with JSP author Duane K. Fields and Mark A.Kolb pages 543 publisher Manning rating 8.5 reviewer Gavin Bong ISBN 1884777996 summary Comprehensive coverage of JSP1.1. Suitable for beginning to intermediate Java developers.

Prologue

Before I proceed with the review, I feel obligated to respond to Jayakrishnan's review of Core Servlets and JSP and Slashdot readers' comments.

I share the sentiments of most people that the use of JSP scriptlets (Model 1) is bad practice. The mantra, "Thou shalt not mix HTML and Java code," should be tattooed onto every JSP developer's forehead. And as the author and readers have suggested, either choose a Model 1.5 (JSP or custom tags with JavaBeans) or Model 2 (MVC) to implement moderate- to high-complexity Web applications.

However, I believe that the authors of this first generation of JSP books need to inform the populace of what JSP is fully capable of (warts and all) -- in order for developers to appreciate the other paradigms. And beyond that, these authors must then educate on how not to use JSP. And I believe that will be the difference between a complete JSP book and an incomplete one.

Secondly, JSP Model 1 has been often described as "servlets lite." It is a good paradigm for prototyping servlets. For example, SOAP4J (IBM's SOAP framework) was released using a JSP scriptlet to dispatch SOAP RPC invocations. The software has since been donated to the Apache group and in the latest public release; the aforementioned JSP scriptlet is now a servlet.

So on that note, let me begin the review.

Topics covered

The book starts with a survey of precursor technologies to JSP in Chapter 1 and quickly moves into the real subject matter. It is clear from the start, that this book is written with the Java programmer in mind. I'd say that only the first five chapters are useful reading for a JSP page designer. Concepts like "How to setup a JSP/Servlet engine?", "Incorporating applets with tag," JDBC, JNDI, and EJB are either relegated to the Annexes or lightly mentioned before detailed treatment follows. The authors only cite HTML and Java as prerequisites but it's more accurate to say that readers also need to have some knowledge of core J2EE services like servlets. Here's a tip: have the JSP v1.1 and Servlets v2.2 specifications within close reach when reading the book.

The book covers all the core JSP topics; here's a sampling:

1. JSP and JavaBeans
The book provides a very readable introduction to JavaBeans for those unfamiliar with it. This is required reading for those implementing the Model 1.5 architecture. However, features specific to visual-oriented beans are not covered. Page designers should specifically devour Chapter 5 on JSP bean tags. The two notable samples provided are:
  • CachedRowSet Bean - An example of paging through results using the JDBC 2.0 RowSet interface.
  • JDBC Transaction Processing - An example of maintaining a JDBC transaction across several JSP pages using a Database Connection Bean and JSP implicit objects.
2. JSP Performance/Scalability
Performance and scalability issues are discussed accross several chapters. The authors attribute JSP's performance to servlet performance, which is tied to JVM server memory. No rule of thumb on sizing JVM server memory is given, but a tip is offered on how to use the serializable interface to estimate the size of Java objects that will be placed in the session object.

Session migration over multiple load-balanced machines is touched upon lightly but no technical details were offered. I would have liked to see a practical example on session persistence coupled with a use case of load balancing a JSP website. It's unfortunate also that the authors didn't think that database connection pooling warrants a practical example.

3. Multithreading
Throughout the book, readers are reminded to be aware of thread safety issues when dealing with shared resources (e.g. JDBC Connections). This tip is offered: "Examine all static variables & objects whose scope is session or application."

4. Exception Handling
A comprehensive coverage on how to handle exceptions in a JSP web application is provided and covers these areas:

  • Error pages in JSP
  • Null properties in JavaBeans
  • Undefined values in Database tables
  • Handling exceptions in servlets (JSP Model 2)
5. JSP Web application architectures
In Chapter 8, the page centric architecture (Model 1) is compared to a servlet centric one (Model 2). A discussion on the servlet RequestDispatcher interface culminates with a sample, that demonstrates how a servlet dictates application flow; relegating JSP pages to provide only presentation services, when called upon. A more complicated sample using this architecture is developed in Chapter 9.

6. Deployment
The book provides complete information on WAR files and Deployment Descriptors.

7. Three chapters of code samples
One full chapter is dedicated to a sample implementation of a real world example of a faq-o-matic tool. Also provided are two chapters of code snippets for Web-based functionality like form handling, cookie management and JSP's marriage with Javascript.

8. Custom tags
The last two chapters are dedicated to this very unique feature of JSP and in it they provide sample custom tags for content substitution and translation, coverage on how to package taglibs and more advanced techniques incorporating Java reflection in custom tag helper classes.

Weaknesses

The book comes with eight pages of errata - mainly spelling/naming errors in the code. I think publishers need to ensure that code be proofread as diligently as the prose. Fortunately the book has a Web site (taglib.com) with a link to a Web-based public forum.

The JSP API in Annex E is presented in the same style as Oreilly's Java in a nutshell book. A UML diagram would have been nice.

And finally, just like in the Core Servlets and JSP book; there's no mention of i18n or security. But this is probably a moot point since you gain i18n features directly from the Java language itself and the "contentType" @page directive attribute. Security of a JSP application is largely dictated by the Servlet/JSP engine configuration (albeit you can plug in your own authentication/encryption schemes) and would be better covered in a book dedicated to system administration and other deployment issues.

Is it worth buying?

It is important to mention that this book covers JSP 1.1 and Servlet 2.2, the production release of each technology. Recently JSP 1.2 and Servlet 2.3 have both entered the Proposed Final Draft stage. So the question is: should you wait for a new edition? My suggestion is: go buy the ebook version (in PDF) from Manning's website. And at a price of $16.50, that's a steal.

In terms of content, the book offers good value in its coverage of deployment issues, different JSP architectures and not forgetting some really good material on custom tags/taglibs. And by advocating an MVC styled development architecture; everyone from your JSP page designers, JavaBean/servlet developers and DBAs will be less coupled - and your code more maintainable.

Table of contents

  • Chapter 1: Introduction
  • Chapter 2: Fundamentals
  • Chapter 3: Programming JSP scripts
  • Chapter 4: Actions and implicit objects
  • Chapter 5: Using JSP Components
  • Chapter 6: Developing JSP Components
  • Chapter 7: Working with databases
  • Chapter 8: Architecting JSP applications
  • Chapter 9: An example JSP Project
  • Chapter 10: Deploying JSP applications
  • Chapter 11: Performing common JSP tasks
  • Chapter 12: JSP by example
  • Chapter 13: Creating custom tags
  • Chapter 14: Implementing advanced custom tags
  • Annex A: Running the reference implementation
  • Annex B: Incorporating Java applets
  • Annex C: JSP resources
  • Annex D: JSP syntax reference
  • Annex E: JSP API reference

Besides the PDF version, you can also purchase this book at Fatbrain.

6 of 102 comments (clear)

  1. Re:CPU power needed to backend JSP pages? by JohnZed · · Score: 3

    I run a JSP-based intranet on a 400 mhz celeron with 64 megs of RAM and it could definitely use more memory (buying it next week), but otherwise it runs very quickly and smoothly. Choose your JVM wisely (Sun's tend to be lower memory usage, IBM's tend to be faster), use a good servlet engine (Resin from www.caucho.com is excellent, but Jakarta is pretty slow), and put in a lot of RAM. I don't know about 200 mhz, though. . . that's probably a little lower than I'd use, especially if it also includes to database.
    --JRZ

  2. Re:Java sucks! by macpeep · · Score: 3
    Sure, Java has it's drawbacks (hint: where is UDP?), but it has a lot more positives than negatives, in my opinion.

    UDP? As in UDP/IP? It's right there with the rest of the networking classes: java.net in such classes as DatagramSocket, DatagramPacket and DatagramSocketImpl.

  3. Re:CPU power needed to backend JSP pages? by tshak · · Score: 3

    We've found that with Allaire's JRUN engine, page execution is reasonable on a dual PIII with 256megs of RAM (NT4). We also found it funny that our Allaire Cold Fusion templates could easily out perform our JSP's (sometimes 2:1), but we didn't want to spend the $5K (vs. $1300) on CFEnterprise for the use of CORBA ORBS and EJB's.


    --

    There is no longer anything that can be done with computers that is nontrivial and clearly legal. -- Paul Phillips
  4. Nothing But Good Vibes by scotteparte · · Score: 3
    Before the dot-com slide started to knock out all the loser no-content sites, I worked for one such company. We were using PHP and MySQL to do some CD database stuff, and it was going well until we wanted to implement e-commerce and a universal login system (we had several domains, and wanted one login for all of them). Suddenly, we realized that PHP and MySQL would not be enough for the task at hand. So we bought the JSP book.

    I had never used JSP before - I had never even written Java code! But the book was written well for someone with a background in scripting languages, and I found myself working with JSP projects easily in no time at all. I even learned Java from that book, and did so well enough to get a new job and excel at it.

    As far as the book is concerned, there are two parts which especially interested me. The first was their overview of Javabeans, which was done clearly and concisely. However, you should know that when I set up the Apache Tomcat JSP server, Javabeans were busted pretty bad (just a warning).

    The FAQ example (I believe it is chapter 9) was also excellent, because it introduced some very good methods for web application design. The first is the FAQRepository, which encapsulates DB calls into a single class. This enhances portability and allows changes to be implemented quickly in the case of a DB software or design change. The second is the so-called "octopus" design, whereby an intelligent central servlet does the bulk of the processing, and then passes control off to a JSP "tentacle" for minor alterations and display. This keeps code clean and organized, and allows for great scalability.

    I would highly recommend this book to anyone looking to learn JSP as well as develop a strong technique. I know it did wonders for me.

    Sorry about all the buzzwords ;)

  5. Dynamic Web Content? Philip & Alex. by LionKimbro · · Score: 4

    Sure, you could read this book...

    OR, you could read Philip and Alex's Guide to Web Publishing, and learn everything there is know about creating dynamic web sites, for free. That's right; click on the book, and you'll be face to face with one of the best books (and websites) that I have ever read, period.

    I've bought the book 3 times in print, because it has the highest circulation amongst my book collection.

  6. Re:Garbage by spooge21 · · Score: 5

    You like reading Slashdot, right? Slashdot could be written in Java using JSP for page generation. This is the type of dynamic content that the author is referring to.

    I REALLY wish people would stop immediately associating Java with eye-candy applets. This is, IMHO, the weakest use for Java.

    As a server side language Java is extremely powerful, primarily due to the huge number of APIs available but also due to the basic design of the language and the core API. Java also promotes code reuse better than any mainstream language out there (once again this is my opinion).

    If you don't like Java as a server side language then don't use it. But please, stop saying Java == applets or JavaScript and using that as a reason to trash the Java platform.