MVC
Model-View-Controller (MVC) Is a widely used architecture that helps developers organize and
structure applications effectively. It separates the application into three main components: Model,
View, and Controller.
The Model-View-Controller (MVC) is an architectural that separates an application into three main
logical components: the model, the view, and the controller. Each of these components are built to
handle specific development aspects of an application. MVC is one of the most frequently used industry-
standard web development framework to create scalable and extensible projects.
it is provide abstraction servlet and JSP technology and web-Service framework
The Front Controller in MVC serves as a centralized entry and exit point for handling multiple requests
and responses. It ensures that all incoming requests pass through a single point, where they can be
processed, routed, or pre-processed with tasks like logging, authentication, or error handling.
view Management ::
sending the results /output generated by Handler class by selecting appropriate view comp having loose
coupling is called is called view management
MVC (Model-View-Controller), view management is the process of handling the presentation layer—
that is, how the data is displayed to the end user in a structured and visually meaningful way.
Pros of MVC:
Organized: Keeps code clean by separating tasks (data, logic, and UI).
Easier Changes: You can update the design (View) without affecting the logic (Model).
Teamwork-Friendly: Different people can work on different parts (Model, View, Controller) without
stepping on each other's toes.
Cons of MVC:
Too Complex for Small Projects: Setting it up can feel like overkill for simple apps.
Takes Time to Learn: If you're new, it might take a while to fully understand.
More Code: You might need to write extra code compared to simpler approaches.
with respect to mvc architecture each web-application contains
FrontController servlet :: 1
Controller /Handler classes :: 1 per module
MVC
Service classes :: 1 per module
DAO classes :: 1 per dab table or 1 for related 3 / 4 table
Front Controller:
1-Oversees and coordinates the entire request lifecycle.
Role: Acts as the central entry point for all incoming requests in an application
Scope: Handles routing, request preprocessing (e.g., authentication, logging), and decides which handler
or controller to delegate the request to.
Purpose: Provides a centralized architecture to manage request flow
Handler Class:
1-Deals with the business logic and details of a single request, as assigned by the Front Controller.
Role: Processes specific types of requests as directed by the Front Controller
Scope: Focuses on handling the actual logic for a single task, such as querying the database, performing
calculations, or generating a response.
Purpose: Implements the business logic or action required for that specific request.
A handler class (commonly a controller in Spring MVC) is responsible for handling client requests. It acts
as the middleman between the user and the back-end logic.
a Controller Class is commonly used to handle incoming requests and define methods (handler
methods) to process those requests. For example, in Spring MVC:
it Is used for handling specific requests and executing the appropriate logic.
MVC
web server
a web server is a software application that serves HTTP requests and responses, enabling
communication between clients (like web browsers) and servers. It is responsible for hosting web
applications, handling client requests (e.g., retrieving web pages, images), and sending back appropriate
responses.
DispatcherServlet
the DispatcherServlet is the central component in frameworks like Spring MVC. It acts as the Front
Controller, meaning it handles all incoming HTTP requests and routes them to the appropriate
components (controllers, views, or models) for processing.
why it simplifies request flow management. Instead of having multiple entry points or duplicating
common logic, it centralizes everything, making the application easier to maintain and extend.
The init() method DispatcherServlet (DS) executes which internally creates ioc container of type
webApplicationContext (ApplicationContext type )
Dispatcher Servlet uses ViewResolver comp as the helper comp to pick the right view comp (jsp file )
for formatting the result
servletContainer is managing DispatcherServlet
DispatcherServlet creates the ioc container , servletContainer managing the ioc container indirectly
the Ds create ioc ,the spring beans like handler classes ,service classes ,DAO classes and etc
how many way WE CAN CONFIGURE /MAP COMP WITH SERVLET container ?
Ans)
approach 1)Declarative approach (using web.xml cfgs )
Approach 2) annotation approach (using @WebServlet)
Approach 3 ) programmatic approach/ Dynamic servlet register (using sc.addServlet(-,-))
Hot and cold deployment Deploy the web applicatation when sever running .is called HOT
Deploy the webapplication when server is in stopped mode called cold
deployment
MVC
Dispatcher Servlet
Spring mvc /springboot mvc are designd around predefined frontController Servlet called
DIspatcherServlet i.e all operations and executation flow in the webApplication happening by
Dispatcher servlet
Spring Boot MVC, the DispatcherServlet is the core component and acts as the Front Controller. It is
responsible for handling all incoming HTTP requests and managing the execution flow of the application.
Executation flow of mvc ::
Client (Browser)
↓
DispatcherServlet (Front Controller)
↓
Handler Mapping → Finds the Appropriate Controller
↓
Controller → Processes Logic and Interacts with Model
↓
Model → Retrieves/Updates Data
↓
MVC
ModelAndView → Returns Data and View Name to DispatcherServlet
↓
View Resolver → Resolves the View
↓
View (e.g., JSP/HTML) → Renders Response
↓
Client (Browser) ← Sends Final Response
MVC
THE MAIN COMPONENT OF SPRING APP ARE ::-
1)Dispatcher servlet (frontCcontoller)
2)Handler/Controller class (java classes having request delegation logics to service
,DAO classes )
3)Handler mapping (To map/link DispatcherServlet trapped request to Handler /
Controller classes )
4)view Resolver (To resolves/Identity correct physical views comp name and
location to format results by excuting the presentation logics )
Handler mapping is a helper or core component which is determining which
controller to invoke based on the URL, request type, or other criteria.
The Handler Mapping identifies the correct Controller or Handler Method to
process the request, using configuration rules or annotations.
A ViewResolver in Spring MVC is like a translator. It takes the logical view name
(e.g., "home") returned by the frontcontroller and converts it into the actual file
or
MVC
Mvc execution flow
MVC
MVC
03/27/25
Data rendering
the process of passing the data from controller class to view comp and keep the data in scope called as data
rendering
we need to place the data in model attribute in control class
And we need to read those data from model attriute in jsp view component
when we send request to mvc application that time dispatcher servlet create a special object called as Binding
awaremethodmap having req scope and handler map can access that object
MVC