• Skip to main content
  • Skip to primary sidebar
  • Skip to secondary sidebar
  • Skip to footer

Computer Notes

Library
    • Computer Fundamental
    • Computer Memory
    • DBMS Tutorial
    • Operating System
    • Computer Networking
    • C Programming
    • C++ Programming
    • Java Programming
    • C# Programming
    • SQL Tutorial
    • Management Tutorial
    • Computer Graphics
    • Compiler Design
    • Style Sheet
    • JavaScript Tutorial
    • Html Tutorial
    • Wordpress Tutorial
    • Python Tutorial
    • PHP Tutorial
    • JSP Tutorial
    • AngularJS Tutorial
    • Data Structures
    • E Commerce Tutorial
    • Visual Basic
    • Structs2 Tutorial
    • Digital Electronics
    • Internet Terms
    • Servlet Tutorial
    • Software Engineering
    • Interviews Questions
    • Basic Terms
    • Troubleshooting
Menu

Header Right

Home » Struts2 » MVC Architecture
Next →
← Prev

MVC Architecture

By Dinesh Thakur

We call Model-2 architecture as MVC (Model View Controller) architecture but Model-1 has Model-1. There are three main components exists in Model 2 architecture: the model, the view, and the controller. Initially the term Model2 is used in the JavaServer Pages Specification version 0.92.

We’ll be covering the following topics in this tutorial:

  • Model Layer
  • View Layer
  • Controller Layer
  • Advantages of MVC Architecture:
  • Rules to be follow while constructing MVC Application:
  • Importance of MVC Application:

Model Layer

The Model layer is the most important part of the MVC paradigm.The Model is implemented by the Action component in Struts2. Model is used to implement all the application data and business logic of web based application or persistence logic. It represents the information of the application. Anything that an enterprise web application persists becomes a part of Model layer.  It is the work of Java developer to develop a model. There are different technologies available in Java to create a model.

1. Java Bean
2. Enterprise Java bean
3. Hibernate
4. Web services
5. EJB
6. Spring
In Struts 2, the model is implemented by the Action component.

View Layer

It is used to implement presentation logic of a web based application. The View layer queries the Model layer for its content and renders it.  View is the work of web designer to create a view component, like Button, Textfield etc. The view is independent and it remains same even if the Application Logic or Business Logic undergoes change. There are many technologies available to implement presentation logic. A View in Struts 2 can be:

1. HTML

2. JSP

3. Freemarker

4. Swing and many more..

Controller Layer

It is used to implement controlling logic or Integration Logic of a web based application. It defines the control flow and execution flow of a web application. Servlet is the only technology to implement controller in a web application. In Struts 2, the role of the controller is played by the StrutsPrepareAndExecuteDisptacher. Filter Dispatcher examines incoming request to determine the Action that will handle the request.

            MVC Architecture

Integration logic is the central logic of the web application which takes the request from client, passes then to model layer resources, gather the results from model layer resources and passes the results to view layer resources. This logic controls and monitors every activity in a web application execution. All interaction between the View layer and the Model layer is managed by the Controller.

In Model View Architecture we integrate all the 4 logic

1. Presentation Logic (View)

2. Business Logic

3. Application Logic and Data Logic (Model)

4. Controlling Logic (Controller)

In a single JSP or SERVLET any change in one logic can affect the other logic.

In MVC Architecture, a servlet acts as a controller and it performs the common operations for all requests like input verification, session management, security etc. We call the servlet as a controller because it knows the entire flow of the web application.

The Controller finds appropriate business logic component for the given request and it will set the data to that component we call that business logic component as a model. By depending on the logic name/Hint returned by the model, the controller selects an appropriate view component this view component get response data from the model and takes this and point to the client browser.

According to MVC Architecture, servlet is a controller, Model is a Bean and JSP is a view.

Advantages of MVC Architecture:

1. Complexity is reduced, because each component has specific logic.

2. We can modify one component, by without affecting the other component.

Rules to be follow while constructing MVC Application:

1. In a web application, there can be any number of model components and any number of view components but there must be a single controller (servlet). This type of controller we call as front Controller.

2. We cannot do the direct linking between two pages, if we directly link two pages we are violating MVC principal because according to MVC the control flow of an application should be maintained controller only.

3. According to MVC architecture model and view component should not talk each other directly. The communication from view to Model and model to view should be done through the intermediator as controller.

4. In MVC, each component should contain its specific logic, we can’t mix-up some other logic into that component.

Importance of MVC Application:

1. While developing web application is Real-time, if one developer wants to understand the flow created by another developer then the entire flow of the application should be maintained at a single place.

2. If an application, follows an MVC principal then it is very simple to increase an application or even decrease an application when it is needed or required.

3. The application implemented using MVC can support different types of client at runtime.

4. While using MVC, it is recommended that use servlet as a controller bean as model and JSP is as view.

You’ll also like:

  1. AngularJS MVC Architecture
  2. MVC Design Pattern
  3. Struts 2 Framework Architecture
  4. What is Network Architecture? Types of Network Architecture
  5. Architecture of JSP
Next →
← Prev
Like/Subscribe us for latest updates     

About Dinesh Thakur
Dinesh ThakurDinesh Thakur holds an B.C.A, MCDBA, MCSD certifications. Dinesh authors the hugely popular Computer Notes blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps.

Dinesh Thakur is a Freelance Writer who helps different clients from all over the globe. Dinesh has written over 500+ blogs, 30+ eBooks, and 10000+ Posts for all types of clients.


For any type of query or something that you think is missing, please feel free to Contact us.


Primary Sidebar

Structs Tutorials

Structs Tutorials

  • Struts - MVC Architecture
  • Struts - Framework Architecture
  • Struts - Struts2 Vs Struts1
  • Struts - Examples
  • Struts - Actions
  • Struts - Overview
  • Struts - Framework

Other Links

  • Structs - PDF Version

Footer

Basic Course

  • Computer Fundamental
  • Computer Networking
  • Operating System
  • Database System
  • Computer Graphics
  • Management System
  • Software Engineering
  • Digital Electronics
  • Electronic Commerce
  • Compiler Design
  • Troubleshooting

Programming

  • Java Programming
  • Structured Query (SQL)
  • C Programming
  • C++ Programming
  • Visual Basic
  • Data Structures
  • Struts 2
  • Java Servlet
  • C# Programming
  • Basic Terms
  • Interviews

World Wide Web

  • Internet
  • Java Script
  • HTML Language
  • Cascading Style Sheet
  • Java Server Pages
  • Wordpress
  • PHP
  • Python Tutorial
  • AngularJS
  • Troubleshooting

 About Us |  Contact Us |  FAQ

Dinesh Thakur is a Technology Columinist and founder of Computer Notes.

Copyright © 2023. All Rights Reserved.