Skip to content
Home » understanding basic architecture of Model, view, controller

understanding basic architecture of Model, view, controller

Below is a clear, structured, and in-depth discussion of Struts – Understanding the Basic Architecture of Model, View, and Controller (MVC), written in a theoretical + flow-oriented manner, suitable for strong conceptual understanding.


Struts Framework: MVC Architecture (Model–View–Controller)

Introduction

The Struts framework is built entirely around the Model–View–Controller (MVC) architectural pattern. The main objective of MVC in Struts is to separate concerns, meaning the presentation logic, business logic, and request-handling logic are kept independent of each other. This separation makes applications easier to develop, test, maintain, and scale.

In Struts, MVC is implemented in a well-defined and centralized manner, where each component has a specific responsibility.


Overview of MVC in Struts

ComponentResponsibility
ModelBusiness logic and data
ViewUser interface
ControllerRequest handling and navigation

Struts acts as a bridge that coordinates communication between these three layers.


1. Model in Struts

Meaning

The Model represents the business logic and data layer of the application. It is responsible for:

  • Processing data
  • Interacting with databases
  • Applying business rules
  • Returning results to the controller

Components of Model in Struts

The Model layer typically consists of:

  • JavaBeans
  • POJOs (Plain Old Java Objects)
  • Service classes
  • DAO (Data Access Object) classes

Role of Model

  • Contains no presentation logic
  • Independent of Struts framework
  • Reusable across different applications
  • Handles data validation at business level

Example Responsibilities

  • User authentication logic
  • Database CRUD operations
  • Calculations and validations
  • Business rule enforcement

📌 In Struts, the Model never directly interacts with JSP pages.


2. View in Struts

Meaning

The View represents the presentation layer of the application. It is responsible for:

  • Displaying data to users
  • Collecting user input
  • Showing responses and messages

Components of View

The View layer is implemented using:

  • JSP pages
  • Struts tag libraries
  • HTML and CSS

Role of JSP in View

  • Displays output received from the controller
  • Uses Struts tags to avoid Java code in JSP
  • Focuses only on UI and formatting

Struts Tag Libraries

Struts provides custom tags such as:

  • <html:form>
  • <html:text>
  • <html:errors>
  • <bean:write>

These tags:

  • Reduce scripting code
  • Improve readability
  • Simplify form handling

📌 View does not contain business logic.


3. Controller in Struts

Meaning

The Controller is the core of the Struts framework. It manages:

  • Client requests
  • Request routing
  • Action invocation
  • Navigation control

Front Controller Concept

Struts uses a Front Controller pattern, where all requests are handled by a single controller.

  • Struts 1: ActionServlet
  • Struts 2: FilterDispatcher / StrutsPrepareAndExecuteFilter

Responsibilities of Controller

  • Receive HTTP requests
  • Identify requested action
  • Call appropriate Action class
  • Interact with Model
  • Decide which View to display

Action Class (Controller Logic)

Role of Action Class

  • Acts as a mediator between View and Model
  • Contains request-processing logic
  • Calls business methods of Model
  • Returns navigation outcome

Flow Inside Action Class

  1. Receive form data
  2. Validate input
  3. Call Model methods
  4. Store results
  5. Forward to appropriate JSP

ActionForm (Struts 1 Only)

Purpose

  • Holds form input values
  • Automatically populated by Struts
  • Acts as a data carrier between View and Controller

📌 In Struts 2, ActionForm is removed and replaced by POJOs.


Request Processing Flow in Struts MVC

  1. Client submits request from browser
  2. Request reaches Front Controller
  3. Controller checks configuration file
  4. Appropriate Action class is identified
  5. Action interacts with Model
  6. Result is returned to Controller
  7. Controller forwards to View (JSP)
  8. JSP renders response to client

Interaction Between MVC Components

FromToPurpose
ViewControllerSends user request
ControllerModelRequests business processing
ModelControllerReturns processed data
ControllerViewSelects response page

📌 Direct interaction between View and Model is avoided.


Benefits of MVC Architecture in Struts

  • Clear separation of concerns
  • Easier maintenance and debugging
  • Reusable and testable components
  • Improved scalability
  • Better team collaboration

Limitations of MVC in Struts

  • Steep learning curve
  • Heavy configuration (especially Struts 1)
  • Controller can become complex
  • Slower development compared to modern frameworks

Conclusion

The MVC architecture in Struts provides a structured and disciplined approach to Java web application development. By clearly separating the Model, View, and Controller, Struts ensures that applications are modular, maintainable, and scalable. The controller-centric design, combined with reusable models and JSP-based views, makes Struts a powerful framework, especially for large and enterprise-level web applications.