Struts 2 follows the Model-View-Controller(MVC) design patterns. The diagram below demonstrates how Struts 2 framework implements MVC components.
- Action - model
- Result - view
- FilterDispatcher - controller
The role each module plays
Controller's job is to map incoming HTTP requests to actions. Those mapping are defined by using XML-based configuration(struts.xml) or Java annotations.
Model in Struts 2 is actions. Each action is defined and implemented by following the framework defined contract(e.g. consist an execute() method). Model component consists the data storage and business logic. Each action is an encapsulation of requests and is placed ValueStack.
View is the presentation component of MVC pattern. In spire of common JSP files, other techniques such as tilts, velocity, freemaker, etc. can be combined to provide a flexible presentation layer.
MVC pattern is the most obvious pattern in Struts 2. You can read the design pattern stories page and know other patterns.
<pre><code> String foo = "bar"; </code></pre>