Spring web MVC - Smart Tech Guides

Latest

Hi this is Sravan Kumar from India. SMART TECH GUIDES is a technical blog. it helps you to learn about Java topics, frameworks and tools like Jenkins, GitHub & related explanations, data base related topics. All these Explanations are explained in simple and understandable manner.

Subscribe Us

SMART TECH GUIDES

Spring web MVC

Spring MVC

Spring is loosely-coupled framework, it is developed in modular fashion.

Spring MVC is one of the modules in spring framework.

Spring MVC framework is built on top of servlet API.

With the help of spring MVC we can develop Web Applications, Distributed Applications.

 

Note: To develop distributed application, we will use SOAP based webservices, RESTful services.

 

Spring web MVC module developed based on two design patterns.

1) MVC design pattern

2) Front controller design pattern.

 

1) MVC design pattern

MVC stands for model view and controller.

 

Model layer is used to hold an application data.

Controller contains business logic of an application.

View represent data in a particular format.

 

application logic is separated in MVC.

 

2) Front controller

Front controller is responsible to perform pre-processing and post-processing of incoming requests.

In spring web MVC based application we will use Dispatcher-Servlet as front controller.

Dispatcher Servlet will be called as spring framework servlet.

 

spring mvc


Steps involved in Spring web MVC application development.

 

1) create new maven project, select maven-archetype-web.

 

2) add web server(tomcat).

 

3) add spring-webmvc dependency in pom.xml.

 

4) create beans configured Java/xml file.

 

5) write business logic inside src/main/java.

 

 

Spring web MVC Request Execution Flow

 

mvc execution flow


1) User enter Http request (URL) in browser, incoming Http request will be received by Dispatcher Servlet.

Dispatcher Servlet is a predefined servlet class in spring MVC.

 

2) Dispatcher Servlet sends requested URL to Handler-Mapper.

 

3) Handler Mapper sends map details to Dispatcher Servlet.

 

4) Dispatcher Servlet will call respective control class methods.

 

5) Controller method will process request and will send ModelAndView object to Dispatcher Servlet.

 

6) Dispatcher Servlet will send view name to ViewResolver.

 

7) ViewResolver will identify view location and extensions and send data to Dispatcher Servlet.

 

8) Dispatcher Servlet will give model and view details to view component.

 

9) Model data will be rendered on view. And sends view back to Dispatcher Servlet.

 

10) Dispatcher Servlet sends final response to User.

  

No comments:

Post a Comment