How Spring MVC Works behind the scenes

Components of a Spring MVC Application
Spring MVC Front Controller
Spring MVC Front Controller
Front controller known as DispatcherServlet Part of the Spring Framework
Already developed by Spring Dev Team
You as a developer will create
Model objects (orange)
View templates (dark green)
Controller classes (yellow)

Spring MVC Front Controller

What is a Controller?
Model
View Template
Spring MVC Configuration Process - Part 1
Add configurations to file: WEB-INF/web.xml
Spring MVC Configuration Process - Part 2
Add configurations to file: WEB-INF/spring-mvc-demo-servlet.xml
Spring MVC example

Development Process
Step 1: Create Controller class
Annotate class with @Controller
@Controller
public class HomeController { }
Step 2: Define Controller method
@Controller
public class HomeController {public String showMyPage() { …
}
}
Step 3: Add Request Mapping to Controller method
@Controller
public class HomeController {@RequestMapping(“/”) public String showMyPage() {
return “main-menu”; }
}
Find View Page Magic

Step 5: Develop View Page
File: /WEB-INF/view/main-menu.jsp
Spring MVC Demo - Home Page