..
The part of Spring in charge of the presentation layer of data specific to Web applications is the Web MVC Framework.
As per the philosophy of Spring also use this form is not necessary to extend or implement any specific interface of the framework.
To implement the MVC, Spring uses three main elements:
The DispatcherServlet is a servlet that is responsible for dispatching all requests (POST, GET, PUT, ...) to the various handlers, so it acts as a Front Controller. The DispatcherServlet, being in effect a servlet must be mapped in web.xml:
<servlet> <servlet-name> dispatcher </ servlet-name> <servlet-class> org.springframework.web.servlet.DispatcherServlet </ servlet-class> <load-on-startup> 1 </ load-on-startup> </ Servlet> <servlet-mapping> <servlet-name> dispatcher </ servlet-name> <url-pattern> / example / * </ url-pattern> </ Servlet-mapping>
The servlet, being fully integrated with the IoC container, has its own WebApplicationContext, which extends the main one, adding all the beans declared in the file WEB-INF / [servlet-name]-servlet.xml.
Particularly between these beans, there will be requests to handlers and View Resolver.
The beans are the handlers that deal is really to serve the request, and are simply POJOs annotated with @ Controller, so now we call them controllers:
@ Controller
{public class ExampleController
@ RequestMapping (value = "/")
public String welcome (Model model) {
model.addAttribute (new Book ());
return "/ book / createBook";
}
}
WEB-INF/dispatcher-servlet.xml and defined in the file:
<! - CONFIGURATION WITH ANNOTATION -> <mvc:annotation-driven /> <bean class="it.mrwebmaster.mvc.ExampleController" scope="session"/>
Through this configuration will be in Spring said that the mapping of the controllers is done through the annotation, so when a request is made the type http://..../example/ DispatcherServlet the controller redirects the call to our example, performing operations on the model (which will be discussed later) and then returns a string that represents the view resolver.
In our example the view resolver is a InternalResourceViewResolver through the string returned by the controller redirects to a jsp:
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" /> <property name="prefix" value="/WEB-INF/jsp/" /> <property name="suffix" value=".jsp" /> </ Bean>In our example, the jsp is / WEB-INF/jsp/book/createBook.jsp

In the following paragraphs will analyze the controller and view resolvers, but besides these, there are other tools that are left free to study for the reader:
| |
Linux (Course)
Complete guide to open-source system. From 49 €. |
| |
PHP (Course)
Full course for creating dynamic Web sites. From 49 €. |
| |
Ruby and Ruby on Rails (Course)
Create software and Web applications with Ruby and RoR. From 39 €. |