Spring Framework and Spring MVC
Soon after the first official release of Spring Framework, Spring’s own MVC based framework came into existence in the form of Spring MVC. The Spring MVC provides rich functionality for building robust web applications and it is available as a separate module within the Spring Framework. Spring MVC is designed in manner similar to Spring in which every piece of logic and functionality is highly configurable in all aspects. Before going into details of Spring MVC, we will see what we mean by MVC.
MVC stands for Model View Controller. In MVC, the model contains the application data as well as various business rules. The controller mediates the incoming request; intern converting the received commands appropriately which can be understood by model and the view. And finally the view can be any output representing the data received from model. MVC has been adapter by most of the modern web application frameworks to be used in web application development very effectively. Spring MVC is one such web application framework. There are various interactions between the various components in an MVC framework, they are:
- A controller can send commands to its associated view to change the view’s presentation of the model.
- A model notifies its associated views and controllers when there has been a change in its state, which can be used to get updated data onto the views.
- A view requests from the Model the information that it needs to generate an output representation.
Figure 11-2 shows interaction of various components in an MVC architecture based on which Spring MVC works.
Figure 11-2. Interaction of components in Model View Controller architecture
Now that you have a clear idea of MVC architecture, we will come back to Spring MVC. Spring MVC is one among the popular web frameworks available today. It is a complete request-based web framework, and controllers in the MVC are the request handlers. It provides a very strong REST (REpresentational State Transfer) foundation and is ideal for handling stateless requests to render the actual representations of resources with very minimal overhead as compared to other web frameworks. Spring MVC will be covered in detail in Chapter 14, but for now, you can see the request flow through a Spring MVC framework in Figure 11-3.
Figure 11-3. Flow of request in a Spring MVC
REST (Representational State Transfer) is an architectural style for distributed system and will be covered in Chapter 16.
Spring Web Flow
Spring Web Flow (SWF) is a component in the Spring Framework Web stack which focuses on the definition and execution of page flows within a web or Portlet application. It actually orchestrates the clients request progress through the flow which has been defined in the SWF definition. The definition given by the client is called as the “Flow Definition”.
There is a bit of history to SWF, it started as a simple extension to the Spring MVC framework providing web flow functionality, developed by Erwin Vervaet in 2004. In 2005 the project was introduced into the Spring portfolio by Keith Donald and grew into the official Spring sub-project.
One of the very notable features of SWF is that it supports a variety of view technologies and integrates with JSP and JSF natively very easily. Introducing SWF into your web application solves conventional issues plaguing any web application like duplicate submissions, browser back and refresh button issues and state collision between browser windows. Figure 11-4 shows the distribution contained in Spring Web Flow 2.
Figure 11-4. Spring Web Flow 2 distribution
We will be covering Spring Web Flow in detail in Chapter 14.
Page Visitors: 2417