2010년 8월 10일 화요일

Struts

1.4.3. Struts: Implementing Model-View-Controller Systems

The MVC paradigm for architecting UI-oriented applications was introduced more than
20 years ago in the Smalltalk environment. Since then, it's become a popular and effective
pattern for designing and managing web applications, and many tools have been created
to support it.

In the MVC pattern, the model represents the data and business logic at the heart of the
application, views represent interactive user interface elements, and the controller links
the views to the model and keeps the application flow moving. In an MVC-based
application, users interact with one or more views in the user interface. Their actions are
passed to the controller, which is responsible for handling them. Based on the user's
actions, the controller can make changes to the application model, generate new views for
the user, or all of the above. Changes in the application model can also generate
notifications directly to views, causing them to change appearance in key ways or adjust
their behavior, based on the new state of the model.
Java servlets and JavaServer Pages provide the essential tools for building web interfaces
in Java, using an object-oriented programming model or a "scripted" web page model,
respectively. Struts is an Apache project built on top of both of these standard Java
technologies, using servlets to implement the controller, both JSPs and servlets to
implement views, and standard Java technologies (such as Java beans and EJBs) to
implement the application model. Struts further facilitates MVC development by providing
a configuration scheme for specifying the page flow of the application based on user actions
and an API for defining action handlers and other key MVC elements.

It's important to point out that the introduction of the JavaServer Faces standard provides
many of the same elements that the Struts project covers. Put another way, Struts was
created to fill a perceived gap between the Java standards at the time and the needs of
enterprise developers. Since then, JavaServer Faces was defined to fill a part of that same
gap. JSF was released in specification form in March 2004, and implementations are now
readily available. The relationship that Struts will have in the future with Java servlets,
JSPs, and JSF still remains to be seen, but in the meantime, Struts remains a popular and
effective tool for MVC development.

A tutorial on Struts is provided in Chapter 19. Because of the functional overlap between
JSF and Struts, the code examples in the two chapters parallel each other and have identical
user interfaces. As a result, you can compare and contrast the implementations to help you
decide which solution is right for your application.