CHAPTER 3: Best Practices in Java EE Web Development 159
Why Use a Framework?
While Java EE does a great job of standardizing the enterprise infrastructure and providing an
application model, there are few major problems associated with it.
Interacting directly with the Java EE components often results in massive
boilerplate code and even code redundancy.
You have to write code for dealing with common business domain problems.
You have to write code for solving architectural domain problems.
You could roll your own framework to address the problems associated with building Java EE based
web applications using OO patterns and Java EE patterns. But writing an in-house framework
entails efforts that are orthogonal to the business goals of the application; in addition, the in-house
framework is unlikely to be upgraded, and the new versions of the in-house framework will never see
the sun, unlike mainstream frameworks that continuously evolve instead of falling into architectural
entropy. With that in mind, it’s time to look at some of the available JVM-based web frameworks (see
Table 3-25). This table is far from exhaustive; a myriad of frameworks are available, but this book will
cover the most successful JVM-based web frameworks listed in the table.
Table 3-25. JVM-Based Web Frameworks
Web Frameworks Category Language Download From
Struts 2 Request-based framework Java http://struts.apache.org/
download.cgi#struts2314
Spring Web MVC Request-based framework Java http://www.springsource.org/spring-
community-download
JSF 2 Component-based framework Java http://www.oracle.com/technetwork/java/
javaee/downloads/index.html
Grails 2 Rapid web development
framework
Groovy http://www.grails.org/download
Play 2 Rapid web development
framework
Java and Scala http://www.playframework.com/download
All the web frameworks listed in Table 3-25 follow the MVC Model-2 architecture, the basic
architectural pattern you learned about in Chapter 2. In a typical web application, there are several
tasks that you want to do for every incoming request, such as encryption. A single controller for
the web application lets you centralize all the tasks that the controller has to perform in a web
application, such as the following:
Centralizing the logic for dispatching requests to views
Checking whether the user requesting an operation has valid authorization
As the MVC-based web application grows larger with more and more views to display, the controller
in the MVC-application model becomes a procedural object that takes too many decisions to render
those views. This problem can be alleviated by using the front controller and configuration metadata,
instead of using pure MVC architecture. This solution is illustrated in Figure 3-19.