More Conference Coverage:
O'Reilly author Jonathan Knudsen (Java Cryptography, Java 2D Graphics, as well as the third edition of Exploring Java and LEGO MINDSTORMS) sent us this report for Monday, March 26, 2001.
Monday was the first day of the second annual O'Reilly Conference on Enterprise Java. I'm filling in for Bob Eckstein, who had a string of bad luck, including a long wait in the Phoenix airport, a flying piece of metal that got stuck in his eye, and a speaker who couldn't get to the show. (Bob -- with that piece of metal in his eye -- covered for the speaker.)
I attended Monday morning's "The Battle Above Servlets" tutorial, a talk given by Jason Hunter, esteemed coauthor of Java Servlet Programming. Jason talked about various technologies that can be used in conjunction with Java Servlets to build Web applications. The motivation is that HTML really has no place in Java servlet code. It comes back to the separation of content and presentation.
Sun Microsystem's official solution for containing HTML is JavaServer Pages (JSP), which is a very powerful tool, but it's easy to mess it up. The thing about servlets is that you don't really want any HTML in a servlet. When you move the HTML into a JSP, though, you usually end up with some Java code in the JSP, particularly if you have to do any iteration or looping. [Editor's note: To learn more about JavaServer Pages, check out O'Reilly's recently released JavaServer Pages.]
To get the Java code out of the JSP, you'll need to use custom tag libraries. Custom tags are tags that look like HTML but are implemented by Java code. At this point, however, you're looking at a pretty complicated solution: JSPs plus a pile of custom tags. You might use prebuilt custom tag libraries like Apache project's Struts; but you're still talking about a pretty complex solution.
There are simpler solutions for moving HTML out of servlets, generically called templating engines or scripting engines. These technologies are specifically designed for separating content and presentation. Jason described two open source templating engines, Tea and WebMacro. They are serious tools. Tea is one of the technologies behind Disney's sites like ESPN.com. WebMacro is the technology behind AltaVista. One wonders about the low visibility of these technologies. Surely Sun is promoting the successes of Disney and AltaVista? Sun has a myopia about JSP and can't admit that there are alternatives for building servlet-based Web applications.
Templating engines ordinarily have their own syntax, but the concepts are similar. You can use Java objects, call methods, get and set properties, and share objects between Web components. Templating engines also offer simple looping capabilities.
Templating engines are generally a much simpler solution than JSP plus custom tags. The moral of the story? Select a technology that meets your needs. Don't be misled by Sun's JSP bias. Evaluate the available technology; choose something that does what you need it to do.
Tea and WebMacro aren't the only game in town, either. Some alternatives are Cocoon, Velocity, and Enhydra. If you're architecting or retooling an application, check out all your options.
Return to Conference Coverage.
Return to ONJava.com.
Copyright © 2009 O'Reilly Media, Inc.