160 CHAPTER 3: Best Practices in Java EE Web Development
When the HTTP request arrives from the client, the front controller looks up in the configuration
metadata file to decide on the right application controller that should handle theHTTP request. The
application controller consists ofthe business logic invocations and presentation logic controls for
the HTTP request.The difference between using pure MVC and the Front Controller pattern with MVC
is that the front controller servlet looks up the configuration metadata to figure out the application
controller that handles the HTTP request processing instead of itself deciding to call specific HTTP
request handler objects.
In essence, this is the pattern that is common to many leading web frameworks. For instance, Struts 2
and Spring Web MVC are front controller–based MVC frameworks that delegate the control to the
application controller using configuration metadata stored in, for example , an XML file. In Struts 2,
the ServletFilter is a manifestation of the front controller in Figure 3-19. In JSF 2, it’s FacesServlet;
in Spring Web MVC, it’s DispatcherServlet; and in Grails 2, it’s the subclass of DispatcherServlet.
This concludes the chapter. From the next chapter onwards, this book will navigate through the
labyrinth of Web frameworks that capitalize on the strengths of Java EE and JVM.
Summary
This chapter focused on evolving the technologies and tools used in a Java EE project. The chapter
introduced you to the common problems associated with developing a web application and showed
how these problems can be solved and how web applications can be made reusable, maintainable,
and extensible by using tools (such as unified EL) available with Java EE.
EL and JSTL are two picture-perfect implementations of the theory of the separation of business
and view concerns, and they can be used to build reusable, easy-to-maintain, function-rich web
applications. This chapter also introduced you to the Java EE web tier patterns and how these
JavaEE patterns provide solutions to the recurring problems in a particular context. Then the chapter
showed how frameworks address architectural and business problem areas by providing patterns-based
generic objects and supporting classes. Finally, the chapter showed how web frameworks relinquish you
from using Java EE design patterns by providing you out-of-the-box best-practice solutions.
Client
Request
Response
Returning
control
View
Rendering Response
Servlet Container
Response Rendering Delegation
Request handling Delegation
Front
Controller
Application
Model Controller
Model
Figure 3-19. MVC with front controller