Current Trends in Java Web Development
By Eric Burke, OCI Senior Software Engineer
In the dark ages (2-3 years ago!), Java applets were the primary tool for creating web-enabled Java programs.
As we all know, applets have not lived up to the initial hype. The reasons are numerous:
- Incompatible web browsers
- Buggy browser JVM implementations
- Slow download and startup times
- Security restrictions
Servlets were the next big thing, resolving many of the applet problems. Servlets execute completely on the server, so there are no issues with browser compatibility or slow download times. Thanks to Java's threading capabilities, servlets execute very fast. They are also relatively easy to develop, so most companies have moved away from CGI programming in favor of servlets.
A companion technology, JavaServer Pages (JSP), arrived shortly after servlets.
JSPs are web page "templates" with special tags embedded into the HTML. These are actually compiled into servlets, so JSPs share the same performance characteristics that have helped make servlets so successful.
Recent Servlet and JSP Developments
The concept of a web application is one of the more interesting developments in the short history of servlets and JSPs. Now, similar to EJB Servers, servlets are said to run inside of containers instead of servlet engines.
Prior to version 2.2 of the servlet specification, deployment of servlets from the development environment to a production server was proprietary and vendor dependent. The new servlet container specification removes most of the vendor-specific deployment issues, making true cross-platform development achievable.
Servlet applications can also be marked as distributable, meaning that they can be deployed to many replicated containers for maximum scalability. Since JSPs are really glorified servlets, the same features are available to JSPs.
Custom tags are the most compelling new feature of JSPs. With custom tags, one can avoid cluttering up HTML code with too much Java code. As more standard tag libraries become available, non-programmers will be able to develop JSPs much more easily.
XML and the Web
The move to XML marks a fundamental shift in the way web applications are developed today. With XML, a clear separation between business data and presentation logic can be enforced. To servlet programmers, this means the end of messy
println() statements that generate tons of HTML.
Instead, a style sheet is used to transform the XML document into something a browser can display, typically HTML. Different style sheets can be employed for browser-specific customizations.
Servlets do not cease to exist because of XML. In fact, a servlet is a key component in an XML-enabled web application, performing many tasks:
- Validating incoming requests
- Creating XML documents
- Applying style sheets to XML
- Selecting the appropriate style sheet
- Performing user session tracking
We have learned a lot about servlets and JSPs over the past few years, and a set of "best practices" is beginning to emerge. Many servlet frameworks are under development, and all seem to offer variants of Model-View-Controller (MVC) architecture.
In the MVC approach, servlets, JSPs, and XML are all utilized in complementary roles. JSPs are generally restricted to the view portion of an application and are best utilized when non-technical people need the ability to quickly update web pages. Programmers can provide custom tags that enable content authors to embed standard elements, such as navigation bars and standard forms.
Servlets are generally considered to be controllers, which mediate between the client web browser and the back-end data sources. It is common to see applications that use a single servlet that immediately passes off control to dedicated controller objects, each of which is dedicated to a particular web page or form.
XML can play the role of both model and view. The XML document presents a structured view of data, while style sheets are a key tool for creating HTML views. XML may be dynamically generated by an EJB component, or it may simply exist on the file system.
A key observation is that a homogeneous approach does not typically offer the best results.
Developing a web site completely in JSP leads to web pages with far too much embedded programming logic. A pure-servlet approach leads to Java programs with too much embedded HTML and an interface that is difficult to update without expert programmers. A pure-XML approach is essentially impossible, because you still need servlets to intercept client browser requests, perform session tracking, and drive the whole transformation process.
Overall, the best strategy is to focus on clean separation of user interface code (HTML) from underlying programming logic.
Software Engineering Tech Trends (SETT) is a regular publication featuring emerging trends in software engineering.