How MVC belongs to only Presentation Layer:-
It is a presentation framework, you may have doubt“How MVC belongs to only presentation layer”.
MVC Framework:
View and Controller belongs to Presentation Layer as Controller takes the URL and directs to appropriate View based on the given URL.
MVC Flow:
- Request comes to the controller, controller decides is there any business logic to be implemented for this request or not.
- If no business logic required it will redirect to the appropriate View. Ex: if we are requesting a login form no business logic required here so controller directly redirect login.jsp .
- If business logic required to the particular request it will call the appropriate Service class to process the request. Based on the service object response, controller redirects to the appropriate view.
- In the view if there is any data is to be shown, then the data will be taken from appropriate model.
With the above diagram View and Controller directly interacting with Presentation Layer.
And model is used by View to show the data.
So MVC belongs to Presentation Layer
MVC in Three tier architecture:
In three tier architecture we have Presentation Tier, Middle Tier, Data Access Tier, simply we can call Presentation layer, Service layer and DAO Layer.
Presentation layer interacts with the Service layer and Service layer interacts with DAO layer.
The Flow will be like this:
- Request comes to controller and controller decides whether this request needs any business logic to be implemented or not
- If no it simply returns a view.
- If yes it interacts with Service Layer and Service Layer interacts with DAO Layer
- Later the based on the response from Service Layer appropriate View will be shown by the Controller.
Spring recommends the same model can be used for presentation layer, In Struts we have form beans as presentation layer model. But in Spring we can use the same model across all the Three Layers.